import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class MyTestGeneric{
public static void main(String args[]) {
new MyFrame99("drawing...");
}
}
class MyFrame99 extends Frame {
ArrayList
MyFrame99(String s) {
super(s);
points = new ArrayList
setLayout(null);
setBounds(300,300,400,300);
this.setBackground(new Color(204,204,255));
setVisible(true);
this.addMouseListener(new Monitor());
}
public void paint(Graphics g) {
Iterator
while(i.hasNext()){
Point p = i.next();
g.setColor(Color.BLUE);
g.fillOval(p.x,p.y,10,10);
}
}
public void addPoint(Point p){
points.add(p);
}
}
class Monitor extends MouseAdapter {
public void mousePressed(MouseEvent e) {
MyFrame99 f = (MyFrame99)e.getSource();
f.addPoint(new Point(e.getX(),e.getY()));
f.repaint();
}
}
这个应该是你要的了,
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Paint extends Applet implements ItemListener
{
//声明组件
Checkbox box1,box2,box3,box4,box5,box6;
CheckboxGroup xBox,yBox;
Label label;
//定义图形标志位和颜色标志位
int flag,color;
public void init()
{
color = 0;
flag = 0;
xBox = new CheckboxGroup();
box1 = new Checkbox("画直线",false,xBox);
box2 = new Checkbox("画矩形",false,xBox);
box3 = new Checkbox("画圆形",false,xBox);
yBox = new CheckboxGroup();
box4 = new Checkbox("蓝色",false,yBox);
box5 = new Checkbox("红色",false,yBox);
box6 = new Checkbox("绿色",false,yBox);
label = new Label("下面是画板",Label.CENTER);
//设为空布局
setLayout(null);
//添加各种组件
add(box1);
add(box2);
add(box3);
add(box4);
add(box5);
add(box6);
add(label);
//设置各组件位置
box1.setBounds(0,0,60,30);
box2.setBounds(60,0,60,30);
box3.setBounds(120,0,60,30);
box4.setBounds(0,30,60,30);
box5.setBounds(60,30,60,30);
box6.setBounds(120,30,60,30);
label.setBounds(0,60,180,30);
//向单选按钮添加监视器
box1.addItemListener(this);
box2.addItemListener(this);
box3.addItemListener(this);
box4.addItemListener(this);
box5.addItemListener(this);
box6.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getItemSelectable() == box1)
{
flag = 1;
repaint();
}
if(e.getItemSelectable() == box2)
{
flag = 2;
repaint();
}
if(e.getItemSelectable() == box3)
{
flag = 3;
repaint();
}
if(e.getItemSelectable() == box4)
{
color = 1;
repaint();
}
if(e.getItemSelectable() == box5)
{
color = 2;
repaint();
}
if(e.getItemSelectable() == box6)
{
color = 3;
repaint();
}
}
public void start(){};
public void stop(){};
public void paint(Graphics g)
{
if(color == 1)
{
g.setColor(Color.blue);
}
if(color == 2)
{
g.setColor(Color.red);
}
if(color == 3)
{
g.setColor(Color.green);
}
if(flag == 1)
{
g.drawLine(70,150,100,180);
}
if(flag == 2)
{
g.drawRect(70,150,30,30);
}
if(flag ==3)
{
g.drawRoundRect(70,150,30,30,30,30);
}
}
}
大哥你给的代码是什么啊。。。就2个小图片
骗点积分有撒意思撒 !!!!鄙视!!