import javax.swing.*;
import java.awt.*;
public class Test
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
NotFrame frame=new NotFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class NotPanel extends JPanel
{
public void paintComponet(Graphics g) //这个函数如何被调用呢,才能让panel显示"Not Hello World"字样???
{
g.drawString("Not Hello World",X,Y);
}
public static final int X=75;
public static final int Y=100;
}
class NotFrame extends JFrame
{
public NotFrame()
{
setTitle("Not");
setSize(W,H);
NotPanel panel=new NotPanel();
add(panel);
}
public static final int W=300;
public static final int H=200;}
执行完毕之后,跟本没出现"Not Hello World"字样,在我检查程序后发现,原程序根本没去调用NotPanel类的paintComponet()这个方法.但我又不知如何去调用它,请指教.
import java.awt.*;
public class Test
{
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
NotFrame frame=new NotFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class NotPanel extends JPanel
{
public void paintComponet(Graphics g) //这个函数如何被调用呢,才能让panel显示"Not Hello World"字样???
{
g.drawString("Not Hello World",X,Y);
}
public static final int X=75;
public static final int Y=100;
}
class NotFrame extends JFrame
{
public NotFrame()
{
setTitle("Not");
setSize(W,H);
NotPanel panel=new NotPanel();
add(panel);
}
public static final int W=300;
public static final int H=200;}
执行完毕之后,跟本没出现"Not Hello World"字样,在我检查程序后发现,原程序根本没去调用NotPanel类的paintComponet()这个方法.但我又不知如何去调用它,请指教.
解决方案 »
- 请教各位大侠像下面这样的链表是不是可以用来连接不同的类啊?
- 怎么给JFrame加载新的皮肤啊...
- 各位大虾,哪有java反射的书啊,实在是不懂
- 关于文件操作的一个问题
- errors.add()的第一个参数的作用是什么啊?用来干什么的啊
- Java+VC+matlab的问题求助
- java里要用一些类,为何有些要new有些不要
- 一个简单的画图程序
- 一个简单再不能简单的问题,可是我却不知道是怎么回事!!!
- 请问这样在技术上是否可行?(我自己写一个程序来监听我的系统上的端口,有些端口已经被别的应用使用,我能够使用什么方法再去监听这个端
- java小程序,没事的朋友试着写一下
- Java读取.bmp的两个方法
还有就是你在调用g.drawString方法时,那个x,y前面还要加入类名吧,那样写好像不符合规范,当然这样的错误它是不会提示出来的,再仔细想想!
相信你现在一定能改正出来了!!