JAVA 中JFrame 中怎样点击一个按钮就在JFrame中画出一个指定的图形?

bobommsky123 2008-03-12 03:59:09
我才开始学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();
}
}
...全文
311 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bobommsky123 2008-03-12
  • 打赏
  • 举报
回复
呵呵,真谢谢你,一下就对了!
对了,我怎么给你分呢,第一次用这个!
hcmsxy 2008-03-12
  • 打赏
  • 举报
回复
???????????? = this.getGraphics().drawLine(100,100 , 100, 200);

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧