swing界面 我想在panel上面画几个图行,然后单击该图形,会有个删除菜单来将该界面从panel上面去掉。请各位大侠帮帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你说清楚点啊 是删除所有的图形 还是某一个 我干脆给你一个橡皮擦程序得了,你自己擦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); }} 我现在在JScrollpane里面,加入个JPanel,我想在拖曳鼠标的时候,JScrollpane随着鼠标的移动来滚动显示 这个很好实现,你将要移除的组件放在JPANEL中,然后要移除的时候,直接调用removeAll()方法就OK了。 java超级困惑呀 java.lang.reflect.InvocationTargetException,在线等待!!! 天涯只看楼主功能 关于updateui 问个新手问题 自定义日历 关于JAVA SQL的问题 access denied 单词词频统计,为什么出不来效果? java方阵求解 java swing 弹出层。。。 问 个 解析全国路 问题
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); }}