
跪求Java高手补写程序,我想(Graphics g)先画好所有再添加到各个button监听器中,有加分
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava.awt.event.Acti...
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();
}
} 展开
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();
}
} 展开
若以下回答无法解决问题,邀请你更新回答
3个回答
展开全部
这个程序没什么问题啊,你是想怎样?说的具体些...............
更多追问追答
追问
我想在Graphtics中用定义的变量先用switch语句画直线,画圆,矩形等图形,就像Windows里的画图一样,我希望你能在我的程序上帮我修改补充下,简单点就行,急用,调色板和画笔的大小就不要了,只要实现我设置的button的功能就行,我很急,希望你快点回复我
追答
你还是问别人吧,你的封装很乱啊。
-----------------------------------------------------------------
可以看一下线程,你可以,每点击一个按钮就开启一个线程,然后重新绘制图形。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
运行有问题吗?
追问
没有啊,我可以运行啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的目的是什么?不是很明白.
追问
就是简单的画笔啊,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询