黑马程序员技术交流社区
标题:
关于(Graphics g)问题。
[打印本页]
作者:
吴小铁你好
时间:
2012-6-9 22:05
标题:
关于(Graphics g)问题。
本帖最后由 吴小铁你好 于 2012-6-19 14:26 编辑
我想(Graphics g)先画好所有再添加到各个button监听器中,求高手补全,我想好久都补不出来
package zhangxiao;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.*;
import javax.swing.WindowConstants;
import java.io.*;
import java.util.*;
public class PainPen extends JFrame{
PainPen(){
super("画图");
JPanel p=new JPanel();
Container c=getContentPane();
c.add(p,BorderLayout.CENTER);
p.setBackground(Color.WHITE);
JButton drLine=new JButton("画直线");
JButton drPen=new JButton("画笔");
JButton drCircle=new JButton("画圆");
JButton drEraser=new JButton("橡皮");
JButton drRect=new JButton("画矩形");
JButton Clear=new JButton("清除");
p.add(drLine);
p.add(drPen);
p.add(drCircle);
p.add(drEraser);
p.add(drRect);
p.add(Clear);
drLine.setBounds(0,0,80, 60);
drPen.setBounds(90, 0, 80, 60);
drCircle.setBounds(180, 0, 80, 60);
drEraser.setBounds(270, 0, 80, 60);
drRect.setBounds(360, 0, 80, 60);
Clear.setBounds(450, 0, 80, 60);
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
drLine.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
drPen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
drCircle.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
drEraser.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
drRect.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
Clear.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
}
public void paint(Graphics g){
Graphics2D g2d = (Graphics2D)g;
int x1,x2,y1,y2,width,height;
boolean First =true;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new PainPen();
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2