import java.awt.*;
import java.awt.event.*;
public class test4 extends Frame implements WindowListener{
public static test4 fr;
public static void main(String args[]){
fr=new test4("hello the first frame!");
Button b1=new Button("press me");
Button b2=new Button("dont't press me");
fr.add("North",b1);
fr.add("South",b2);
fr.pack();
fr.addWindowListener(fr);
fr.setSize(200,300);
fr.setBackground(Color.red);
fr.setForeground(Color.blue);
fr.setVisible(true);
fr.paint(fr.getGraphics());
}
public test4(String str){
super(str);
}
public void paint(Graphics g){
super.paint(g);
g.drawString("12312312312312",100,100);
g.drawString("5555555555555555",150,150);
}
public void windowClosing(WindowEvent e){
System.exit(1);
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}其中
public void paint(Graphics g){
super.paint(g);
g.drawString("12312312312312",100,100);
g.drawString("5555555555555555",150,150);
}
这段代码的super.paint(g)好像有没有没什么关系啊,请问这个例子用这条语句的目的何在
虽然调用了父类的paint()方法,但好像什么事情都没有做
import java.awt.event.*;
public class test4 extends Frame implements WindowListener{
public static test4 fr;
public static void main(String args[]){
fr=new test4("hello the first frame!");
Button b1=new Button("press me");
Button b2=new Button("dont't press me");
fr.add("North",b1);
fr.add("South",b2);
fr.pack();
fr.addWindowListener(fr);
fr.setSize(200,300);
fr.setBackground(Color.red);
fr.setForeground(Color.blue);
fr.setVisible(true);
fr.paint(fr.getGraphics());
}
public test4(String str){
super(str);
}
public void paint(Graphics g){
super.paint(g);
g.drawString("12312312312312",100,100);
g.drawString("5555555555555555",150,150);
}
public void windowClosing(WindowEvent e){
System.exit(1);
}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}其中
public void paint(Graphics g){
super.paint(g);
g.drawString("12312312312312",100,100);
g.drawString("5555555555555555",150,150);
}
这段代码的super.paint(g)好像有没有没什么关系啊,请问这个例子用这条语句的目的何在
虽然调用了父类的paint()方法,但好像什么事情都没有做
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货