快捷导航

这个代码哪位大神可以帮忙改一下。。

import java.awt.*;import java.awt.event.*;import javax.swing.*;public class HelloWorld3 {        public static void main(String[] args){        JFrame frame = new JFrame(" HelloWorld3 ");        frame.add(new HelloComponent3("Hellow"));        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.setSize(300,300);        frame.setVisible(true);        }}class HelloComponent3 extends JComponent implements MouseMotionListener,ActionListener {        String theMessage;        int messageX=125,messageY=95;        JButton theButton;        int colorIndex;        static Color[] someColors={Color.black,Color.red,Color.green,Color.blue,Color.magenta};                public HelloComponent3(String message){                theMessage=message;                theButton=new JButton("change message");                setLayout(new FlowLayout());                add(theButton);                theButton.addActionListener(this);                addMouseMotionListener(this);        }                public void painComponent(Graphics g){                g.drawString(theMessage, messageX, messageY);        }                public void mouseDragged(MouseEvent e){                messageX=e.getX();                messageY=e.getY();                repaint();        }                public void mouseMoved(MouseEvent e){}          public void actionperformed(ActionEvent e){  if(e.getSource()== theButton)          changeColor();  }   synchronized private void changeColor(){          if(++colorIndex==someColors.length)                  colorIndex=0;          setForeground(currentColor());          repaint();  }   synchronized private Color currentColor(){          return someColors[colorIndex];  }        public void actionPerformed(ActionEvent e) {                        } }

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP