g draw Oval50 110 100 30 g draw











- Slides: 11
โปรแกรมวาดรปทรงและแสดงผลขอความโ ดยการใชสแบบตางๆ g. draw. Oval(50, 110, 100, 30); g. draw. String("draw. Oval", 70, 130); import java. applet. *; import java. awt. *; g. set. Color(Color. black); g. fill. Oval(50, 145, 100, 30); g. set. Color(Color. white); 80, 165); public class Colorful. Shape extends Applet g. draw. String("fill. Oval", { g. set. Color(Color. red); g. draw. Arc(10, 28, 180, Font fn; 180, 180); Color c; 70, 195); c = new <html> public void init()g. draw. String("draw. Arc 2", { Color(0, 78, 152); <head> set. Background(Color. light. Gray); g. set. Color(c); Font. BOLD, g. fill. Oval(200, 75, 90); fn = new Font("Tahoma", 12); <title>Colorful. Shape</title> g. set. Color(Color. white); g. draw. String("fill. Circle", 222, } <meta http-equiv="Content-Type" content="text/html; 115); public void paint(Graphics g) { charset=UTF-8"> 215, 135); c = new Color(64, g. set. Font(fn); g. draw. String("(0, 78, 152)", g. set. Color(Color. yellow); 0, 180, 128); 180, 0, 180); </head> g. draw. Arc(10, 20, g. draw. String("draw. Arc 1", g. set. Color(c); g. fill. Arc(300, 20, 180, 0, <body> 70, 40); 90); g. set. Color(Color. magenta); g. draw. Rect(50, 100, 15); <applet code="Colorful. Shape. class" HEIGHT=220 g. set. Color(Color. white); g. draw. String("(64, 0, 128)", 300, g. draw. String("draw. Rect", 70, 62); g. set. Color(Color. blue); WIDTH=500></applet> g. fill. Rect(50, 70, 25); 100, 15); g. set. Color(Color. white); </body> c = new Color(255, 9); g. set. Color(c); 10 g. draw. String("fill. Rect", 80, 82); 132, g. set. Color(Color. green);
ทำงานกบเมาสและคยบอรด private class Text. Listener implements Action. Listener { import javax. swing. *; public void action. Performed(Action. Event e) { import java. applet. *; String ans = new import java. awt. *; String(msg. get. Password()); import java. awt. event. *; label 2. set. Text("Your Message is " + ans); public class Key. Mouse. Test } extends Applet { JLabel label 1, label 2; } JPassword. Field msg; Font fn = new Font("Microsoft Sans Serif", Font. BOLD, 14); private class My. Mouse. Listener implements public void init() { Mouse. Listener { <html> set. Background(Color. cyan); public void mouse. Released(Mouse. Event e) { <head> label 1 = new JLabel("Enter Message", Swing. Constants. CENTER); } label 1. set. Preferred. Size(new Dimension(120, 25)); msg = new public void mouse. Entered(Mouse. Event e) { <title>Key. Mouse. Test</title> JPassword. Field(10); label 2. set. Background(Color. red); <meta http-equiv="Content-Type" content="text/html; label 2 = new JLabel("Show Your Message Here", } Swing. Constants. CENTER); public void mouse. Exited(Mouse. Event e) { charset=UTF-8"> label 2. set. Opaque(true); label 2. set. Background(Color. blue); </head> label 2. set. Foreground(Color. white); label 2. set. Preferred. Size(new } Dimension(200, 25)); public void mouse. Clicked(Mouse. Event e) { <body> label 1. set. Font(fn); msg. set. Font(fn); label 2. set. Font(fn); } <applet code="Key. Mouse. Test. class" width="300"e) { add(label 1); add(msg); add(label 2); public void mouse. Pressed(Mouse. Event msg. add. Action. Listener(new Text. Listener()); } height="70"></applet> 11 label 2. add. Mouse. Listener(new My. Mouse. Listener()); }