当前位置: 技术问答>java相关
----为什么没有"helloworld"?
来源: 互联网 发布时间:2015-02-14
本文导语: 执行时只有一个窗口,没有 "HelloWorld" ?????? import java.awt.*; import java.awt.event.*; import javax.swing.*; class HelloPanel extends JPanel { public void paintComonent(Graphics g) { super.paintComponents(g); g.drawString("HelloWorld",75,100); } } clas...
执行时只有一个窗口,没有 "HelloWorld" ??????
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class HelloPanel extends JPanel
{
public void paintComonent(Graphics g)
{
super.paintComponents(g);
g.drawString("HelloWorld",75,100);
}
}
class HelloFrame extends JFrame
{
public HelloFrame()
{
setTitle("hello");
setSize(300,200);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Container contentPane = getContentPane();
contentPane.add(new HelloPanel());
}
}
public class HelloTest
{
public static void main(String[] args)
{
JFrame frame = new HelloFrame();
frame.show();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class HelloPanel extends JPanel
{
public void paintComonent(Graphics g)
{
super.paintComponents(g);
g.drawString("HelloWorld",75,100);
}
}
class HelloFrame extends JFrame
{
public HelloFrame()
{
setTitle("hello");
setSize(300,200);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Container contentPane = getContentPane();
contentPane.add(new HelloPanel());
}
}
public class HelloTest
{
public static void main(String[] args)
{
JFrame frame = new HelloFrame();
frame.show();
}
}
|
把public void paintComonent(Graphics g)改为public void paint(Graphics g)
|
paint就像main一样