亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

這個代碼哪位大神可以幫忙改一下。。

這個代碼哪位大神可以幫忙改一下。。

慕粉4326657 2016-11-23 15:44:13
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) { }? }
查看完整描述

3 回答

  • 3 回答
  • 1 關注
  • 1274 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號