这里是源码:
package demo; import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class imgshow extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public JButton b;
mycanvas a;
public JTextField jt;
Connection kt;
String getname;
int x=0;
int y=0;
public List<Integer> getinput;
public List<Integer> getoutput;
Statement sm;
class mycanvas extends Canvas{
/**
*
*/
private static final long serialVersionUID = 1L;
public void paint(Graphics g){
g.drawLine(30, 0,30,500);
g.drawLine(30,500,600,500);
g.drawString("100",30,400);
g.drawString("200", 30, 300);
g.drawString("300", 30, 200);
g.drawString("400", 30, 100);
g.drawString("100", 130,500 );
g.drawString("200", 230,500 );
g.drawString("300", 330,500 );
g.drawString("400", 430,500 );
g.drawString("500", 530,500 );
g.drawString("支出/收入", 30,520 );
g.setColor(Color.red);
g.drawLine(30, 500, x,y);
//g.drawLine(x,y ,430,200);
g.drawString("balance", 400, 100);
g.setColor(Color.BLUE);
g.drawLine(30, 500, 400, 100);
}
}
imgshow(){
this.setSize(1000,700);
this.setLayout(null);
this.setTitle("波浪线展示:");
b=new JButton("确定查询");
b.setBounds(900, 00, 100, 30);
a=new mycanvas();
a.setBounds(0, 0,700, 600);
jt=new JTextField();
jt.setBounds(900, 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) {
String getname=get.getText();
thread thread1=new thread(getname);
thread1.start();
SwingUtilities.invokeLater(thread1);
}
}
class thread extends Thread {
// TODO Auto-generated method stub
private String name;
thread(String name){
this.name=name;
}
public void run(){
try {
List<Integer>getinput=new ArrayList<Integer>();
List<Integer>getoutput=new ArrayList<Integer>();
Class.forName("com.mysql.jdbc.Driver");
Connection kt;
kt = DriverManager.getConnection("jdbc:mysql://localhost:3306/bankcount","root","123");
Statement sm=kt.createStatement();
ResultSet rs=sm.executeQuery("select input,output from informations where name='"+name+"'");
while(rs.next()){
getinput.add(rs.getInt("input"));
getoutput.add(rs.getInt("output"));
}
repaint(getinput,getoutput);
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void repaint(List c,List d){
for(int j = 0;j<c.size()-1;j++){
System.out.println(c.get(j));
x=(int)c.get(j)+30;
if((int)c.get(j)<=100){
y=(int) c.get(j)+300;
a.repaint();
}
if((int)c.get(j)<=200&&(int)c.get(j)>100){
y=(int)c.get(j)+100;
a.repaint();
}
if((int)c.get(j)<=300&&(int)c.get(j)>200){
y=(int)c.get(j)-100;
a.repaint();
}
if((int)c.get(j)<=400&&(int)c.get(j)>300){
y=(int)c.get(j)-300;
a.repaint();
}
}
}
public static void main(String args[]){
new imgshow();
}
}这里是未按下按钮的效果: 
这里是按下按钮后效果: 
我的本意是从数据库里取得值以后,在画出图,
但是不知道为什么只能显示数据库里的最后一条数据,但是我像画出所有的数据库里的数据,但是根本不行。
下面我给出理想的效果图:
请问大师该怎么做才能实现,我实在看不穿。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
等vcxdsfsd无法 发的广泛的是个破发送到 ######?????兄弟别逗我。######显示的数据要在paint里一次画完,儿不是画了一条repaint再画,为了效率最好建立图片缓存