我想在panel上面画几个图行,然后单击该图形,会有个删除菜单来将该界面从panel上面去掉。请各位大侠帮帮忙

解决方案 »

  1.   

    你说清楚点啊  是删除所有的图形   还是某一个   我干脆给你一个橡皮擦程序得了,你自己擦
    import java.awt.event.*;
    import java.awt.*;
    import java.applet.*;
    import javax.swing.JColorChooser;public class DrawPicture extends Applet implements MouseMotionListener,
    ActionListener { Button button1, button2, button3;
    Color c;
    int x, y;
    int con;
    int 橡皮擦通知, 清除通知; public void init() {
    con = 5;
    button1 = new Button("调色板");
    button2 = new Button("橡皮擦");
    button3 = new Button("清除");
    add(button1);
    add(button2);
    add(button3); 橡皮擦通知 = 0;
    清除通知 = 0; button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this); addMouseMotionListener(this); } public void paint(Graphics g) {
    g.setColor(c);
    g.fillOval(x, y, con, con);
    if (橡皮擦通知 == 1 && 清除通知 == 0) { g.clearRect(x, y, 10, 10); } else if (清除通知 == 1 && 橡皮擦通知 == 0) { g.clearRect(0, 0, getSize().width, getSize().height); }
    } public void mouseDragged(MouseEvent e) {
    x = e.getX();
    y = e.getY();
    repaint();
    } public void mouseMoved(MouseEvent e) { } public void actionPerformed(ActionEvent e) {
    if (e.getSource() == button1) {
    c = JColorChooser.showDialog(this, "调色板", Color.orange); } else if (e.getSource() == button2) {
    橡皮擦通知 = 1;清除通知=0;
    repaint(); } else if (e.getSource() == button3) {
    清除通知 = 1;橡皮擦通知=0;
    repaint(); } } public void update(Graphics g) {
    paint(g); }}
      

  2.   

    我现在在JScrollpane里面,加入个JPanel,我想在拖曳鼠标的时候,JScrollpane随着鼠标的移动来滚动显示
      

  3.   

    这个很好实现,你将要移除的组件放在JPANEL中,然后要移除的时候,直接调用removeAll()方法就OK了。