السلام
لوسمحتم انا عندي هوموورك وعندي مشكله بالحل وهذا الكود بjava applet
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class Hw5 extends Applet {
Color textColor=Color.black;
Color backGroundColor;
MyCanvas myCanvas = new MyCanvas();
Label label = new Label("new Phrase:");
TextField text = new TextField(20);
Choice choice = new Choice();
List list = new List();
Button black = new Button("Black");
Button blue = new Button("Blue");
Button cyan = new Button("Cyan");
Button dark = new Button("Dark Gray");
Button gray = new Button("Gray");
Button green = new Button("Green");
Button light = new Button("Light Gray");
Button magenta = new Button("Magenta");
Button orange = new Button("Orange");
Button red = new Button("Red");
Button white = new Button("White");
Button yellow = new Button("Yellow");
public void init() {
list.addItem("JAVA is Fun!");
list.addItem("Foo + Bar = FooBar");
list.addItem("Hello, World!");
list.addItem("Goodbye Cruel World");
choice.addItem("Black");
choice.addItem("Blue");
choice.addItem("Cyan");
choice.addItem("Dark Gray");
choice.addItem("Gray");
choice.addItem("Green");
choice.addItem("Light");
choice.addItem("Magenta");
choice.addItem("Orange");
choice.addItem("Red");
choice.addItem("White");
choice.addItem("Yellow");
Panel p = new Panel();
p.add(choice);
p.add(black);
p.add(blue);
p.add(cyan);
p.add(dark);
p.add(gray);
p.add(green);
p.add(light);
p.add(magenta);
p.add(orange);
p.add(red);
p.add(white);
p.add(yellow);
black.addActionListener(myCanvas);
blue.addActionListener(myCanvas);
cyan.addActionListener(myCanvas);
dark.addActionListener(myCanvas);
gray.addActionListener(myCanvas);
green.addActionListener(myCanvas);
light.addActionListener(myCanvas);
magenta.addActionListener(myCanvas);
orange.addActionListener(myCanvas);
red.addActionListener(myCanvas);
white.addActionListener(myCanvas);
yellow.addActionListener(myCanvas);
p.setLayout(new GridLayout(0,1,3,3));
Panel q = new Panel();
q.add(label);
q.add(text);
Panel r = new Panel();
r.add(new MyCanvas());
r.add(list);
r.setLayout(new GridLayout(0,1,3,3));
setLayout(new BorderLayout(0,10));
add(BorderLayout.WEST,p);
add(BorderLayout.SOUTH,q);
add(BorderLayout.CENTER,r);
}
class MyCanvas extends Canvas implements ActionListener { //.. note: inner class
public void paint(Graphics g) {
int i,k=0;
for (i=0;i<getSize().height;i++) {
g.setColor(Color.gray);
g.drawLine(0,k,k,0);
k=k+13;
}
k=0;
int x=getSize().height;
for (i=0;i<getSize().height;i++) {
g.setColor(Color.gray);
g.drawLine(0,x,k,getSize().height);
k=k+13;
x=x-13;
}
g.setColor(textColor);
g.drawString("Hello World!", getSize().width/2,getSize().height/2);
} //end of paint method
public void actionPerformed(ActionEvent e){
if (e.getSource() instanceof Button) {
Button x = (Button) (e.getSource());
if (x==black) {
textColor=Color.black;
}
if (x==blue) {
textColor=Color.blue;
}
if (x==cyan) {
textColor=Color.cyan;
}
if (x==dark) {
textColor=Color.darkGray;
}
if (x==gray) {
textColor=Color.gray;
}
if (x==green) {
textColor=Color.green;
}
if (x==light) {
textColor=Color.lightGray;
}
if (x==magenta) {
textColor=Color.magenta;
}
if (x==orange) {
textColor=Color.orange;
}
if (x==red) {
textColor=Color.red;
}
if (x==white) {
textColor=Color.white;
}
if (x==yellow) {
textColor=Color.yellow;
}
repaint();
} //end of actionPerformed
}
}
}عباره عن مجموعه من components عندي مشكله بالbuttons الي على يسار شاشه
لمن ادوس على اي واحد فيهم يعطي لون للكتابه انا عندي مشكله بالنقطه فاتمنى احد يشوف الكود ويصلحلي الخطأ لو يقدر
اهوه شغال بس يشتغل اللون كتابه الي اختاره لمن اغير حجم applet
بس لمن يكون applet ثابت لون كتابه مايتغير
اتمنى احد يرد بسرعه تسليمه اليوم:)