1 simple phone applet lab 10. 2 mobile phone display area send, menu and end numbers 0-9 * and #

25
1 Simple Phone Applet Simple Phone Applet Lab 10 Lab 10

Post on 19-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

1

Simple Phone AppletSimple Phone AppletSimple Phone AppletSimple Phone Applet

Lab 10Lab 10

2

Mobile Phone

Display Area

Send, Menu and End

Numbers 0-9

* and #

3

Layout of Mobile PhoneDisplay Area

Send, Menu and End

Numbers 0-9

* and #

4

You can type in the display area

5

You can press numbers

6

PanelPanel

to make Applet or Frame layout easier, we break a frame up into regions and compose each of them separately. Each region is called a Panel. Each can have its own different LayoutManager. Panels don't have any visible bounding lines. We can delimit them with differing background colours. If we want something to draw on with drawString and drawLine normally you would use a Canvas.

7

Button

8

Code of red colorimport java.applet.*;import java.awt.*;

public class lab10 extends java.applet.Applet { public void init() { setLayout(new FlowLayout());

setBackground(Color.red);add(new Label("<<"));add(new Button("How are you DCO students"));add(new Label(">>"));

}}

9

Button of mobile phones

10

Source Codeimport java.applet.*;import java.awt.*;

public class lab101 extends java.applet.Applet { public void init() {

String str; setLayout(new FlowLayout());setBackground(Color.red);add(new Button("send"));

add(new Button("menu")); add(new Button("stop"));

for (int i = 1; i <9; i++) {str = "" +i; //Integer to Stringadd(new Button(str));

} add(new Button("*")); add(new Button("0")); add(new Button("#")); } }

11

HTML with different width<html>

<head><title>Maximum Using

Array</title></head>

<body>

<applet code = "lab101.class" width = 100 height = 350>

</applet>

</body>

</html>

12

Use GridLayout String str;

setLayout( new GridLayout( 5, 3 )); // row 5: col :3

setBackground(Color.red);

add(new Button("send"));

add(new Button("menu"));

add(new Button("stop"));for (int i = 1; i <10; i++) {str = "" +i; //Integer to Stringadd(new Button(str));

} add(new Button("*")); add(new Button("0")); add(new Button("#"));

13

The source codeimport javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.*;

public class Grid_JApplet1 extends JApplet{ public void init() { // Swing adds JComponents to the container's // contentPane rather than directly to the panel // as with the AWT. Container contentPane = getContentPane();

// Modify and add code between this line //--------------------------------------------

// Create an instance of a JPanel sub-class GridPanel gridPanel = new GridPanel();

// And add one or more panels to the JApplet panel. contentPane.add(gridPanel);

//-------------------------------------------- // and this line. }

}

// A sample JPanel class for holding componentsclass GridPanel extends JPanel{ GridPanel() { // Modify and add code between this line //--------------------------------------------

String str;setLayout( new GridLayout( 5, 3 )); // row 5: col :3setBackground(Color.red);add(new Button("send"));

add(new Button("menu")); add(new Button("stop"));

for (int i = 1; i <10; i++) {str = "" +i; //Integer to Stringadd(new Button(str));

} add(new Button("*")); add(new Button("0")); add(new Button("#")); //-------------------------------------------- // and this line. }}

14

The HTML

15

Text Field

TextFieldA TextField is a scrollable text display object with one row of characters. The preferred width of the field may be specified during construction and an initial string may be specified.

16

Simple Text Field

17

Source Code

18

Sourceimport java.awt.*; import java.applet.Applet; public class TextFieldSimpleTest extends Applet { public void init() {

TextField f1 = new TextField("type something");

add(f1);

} }

19

Text AreaTextAreaA TextArea is a multi-row text field that displays a single string of characters, where newline ('\n' or '\n\r' or '\r', depending on platform) ends each row. The width and height of the field is set at construction, but the text can be scrolled up/down and left/right.

20

Text Area

21

Source Codeimport java.awt.*; import java.applet.Applet; public class TextAreaSimpleTest extends Applet { TextArea disp; public void init() { disp = new TextArea("Code goes here", 10, 30); add(disp); } }

22

Scroll

23

Source codeimport java.awt.*; import java.applet.Applet; public class TextAreaScroll extends Applet { String s = "This is a very long message " + "How are you DCO students " + "are you learning Java?"; public void init() { add(new TextArea (s, 4, 15, TextArea.SCROLLBARS_NONE)); add(new TextArea (s, 4, 15, TextArea.SCROLLBARS_BOTH)); } }

24

Source code of Phone

25

Diagram