开发者社区> 问答> 正文

谁会用JAVA写个波形图?:报错

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函数里面时便有用,但是这样按钮就没有意义了

展开
收起
kun坤 2020-06-09 09:30:07 419 0
1 条回答
写回答
取消 提交回答
  • ######用jfreechart######public void actionPerformed(ActionEvent e) {

        // TODO Auto-generated method stub

        thread thread1=new thread();

        SwingUtilities.invokeLater(thread1);

    } ######谢谢你完美的解决了我的问题,HAHA######我会######a.repaint();

    ######谢谢你完美的解决了我的问题,原来是对 是这么简单的问题啊

    2020-06-09 09:30:13
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载