谁会用JAVA写个波形图?

新手小白 发布于 2015/12/07 23:25
阅读 577
收藏 0
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class imgshow extends  JFrame {
public JButton b;
mycanvas a;
public int x;
public int y;
class mycanvas extends Canvas{
public void paint(Graphics g){
super.paint(g);
g.drawLine(30, 30,30,400);
g.drawLine(30,400,500,400);
g.setColor(Color.red);
g.drawLine(30, 400, x,y);
}}
imgshow(){
  this.setSize(700,700);  
  this.setLayout(null);
      this.setTitle("波浪线展示:");
      b=new JButton("确定查询");
      b.setBounds(600, 00, 100, 30);
     a=new mycanvas();
     a.setBounds(0, 0, 500, 500);
     jt=new JTextField();
     jt.setBounds(600, 30, 100, 30);
      this.add(a);
      this.add(jt);
      this.add(b);
      b.addActionListener(new act(jt));
      this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
    class act implements ActionListener{
    JTextField get;
    act(JTextField get){
    this.get=get;
    }
    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub

  thread thread1=new thread();

thread1.start();

}

 class thread extends Thread(){

// TODO Auto-generated method stub
System.out.println(getinput);
repaint();
x=900;
y=300;
}
public static void main(String args[]){
new imgshow();
}
}
 

看上面这段代码,本来设想是按下按钮之后线条就会变化,但是根本没变。

奇怪的如果我吧thread1.start()放在imgshow函数里面时便有用,但是这样按钮就没有意义了


加载中
0
0
1
1505412718
public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub

    thread thread1=new thread();

    SwingUtilities.invokeLater(thread1);

}

新手小白
谢谢你完美的解决了我的问题,HAHA
0
0x0001
0x0001
a.repaint();
新手小白
谢谢你完美的解决了我的问题,原来是对 是这么简单的问题啊
返回顶部
顶部