我才开始学JAVA,想试写一个简易画图板!但是不知道JFrame中到底有哪些现成的画图的方法,请教各位高手!我定义了两个按钮,一个是关闭按钮,一个想用来点击就画一条直线,可是不知道怎么弄!下面是代码,在ELSE IF里怎么弄呢?import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class dr extends JFrame implements ActionListener{
JButton close;
JButton line;
public dr(){
line= new JButton("----");
line.setBounds(10,200,50,40);
line.setForeground(Color.blue);
line.setBackground(Color.pink);
close = new JButton("x");
close.setBounds(10,300,50,40);
close.setForeground(Color.red);
close.setBackground(Color.pink);
add(close);
add(line);
close.addActionListener(this);
line.addActionListener(this);
setLayout(null);
setBackground(Color.yellow);
setTitle("~~~~~~~~~画板~~~~~~~~~");
setSize(400,600);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==close) dispose();
else if(e.getSource()==line){
???????????
}
}
public static void main(String[] args){
new dr();
}
}
import java.awt.*;
import java.awt.event.*;
public class dr extends JFrame implements ActionListener{
JButton close;
JButton line;
public dr(){
line= new JButton("----");
line.setBounds(10,200,50,40);
line.setForeground(Color.blue);
line.setBackground(Color.pink);
close = new JButton("x");
close.setBounds(10,300,50,40);
close.setForeground(Color.red);
close.setBackground(Color.pink);
add(close);
add(line);
close.addActionListener(this);
line.addActionListener(this);
setLayout(null);
setBackground(Color.yellow);
setTitle("~~~~~~~~~画板~~~~~~~~~");
setSize(400,600);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==close) dispose();
else if(e.getSource()==line){
???????????
}
}
public static void main(String[] args){
new dr();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货