BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #19970同步于 2011/9/6
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

求教一个简单的java可视化问题

lianjun
2011/9/6镜像同步2 回复
public class Main { public static void main( String args[] ) { FFrame frame = new FFrame(); JMenuBar menubar = new JMenuBar();//添加菜单 frame.setJMenuBar(menubar); JMenu game = new JMenu("game"); JMenu option = new JMenu("Option"); menubar.add(game); menubar.add(option); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } public class FFrame extends JFrame{ public FFrame() { setSize(500,665); PPanel panel = new PPanel(); add(panel); } } public class PPanel extends JPanel{ public void paintComponent(Graphics g) { g.drawString("出错了", 0, 10); } public PPanel() { Timer time = new Timer(1000, new DropActionListener()); time.start(); } public class DropActionListener implements ActionListener { public void actionPerformed(ActionEvent event ) { repaint(); } } } //repaint()前后的图像如下。。。怎么改正啊!
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
GacktCamui机器人#1 · 2011/9/6
public void paintComponent(Graphics g) { super.paintComponent(g); g.drawString("出错了", 0, 10); } 注意paintComponent覆盖时都要小心,除非你根本不想把它当panel来使用,否则一定要调父类方法。 【 在 lianjun 的大作中提到: 】 : public class Main { : public static void main( String args[] ) : { : ...................
lianjun机器人#2 · 2011/9/6
唔。。。。确实是忘了调用父类方法了。。 太感谢了!!! 【 在 GacktCamui 的大作中提到: 】 : public void paintComponent(Graphics g) { : super.paintComponent(g); : g.drawString("出错了", 0, 10); : ...................