删除按钮,按钮的图片还在

pcmlose 2011-01-31 11:04:03
还有,删除按钮后的颜色也有点奇怪,但一移动窗口大小就达到正常状态,为什么,怎么改,请高手指导一下谢谢


右键就能添加为按钮添加图片,单击就删除按钮
请自备一张 10X10的222.jpg图片



import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.text.*;
import java.awt.event.*;
public class test extends JFrame implements Runnable{
ImageIcon sweepicon=new ImageIcon("222.jpg");
int main_x=15;
int main_y=12;
int toppanel_height=40;
int height=main_y*20+toppanel_height+68;
int width=main_x*20+15;
public static void main(String[] args){
EventQueue.invokeLater(new Runnable(){
public void run(){
try{
test frame=new test();
frame.setVisible(true);
new Thread(frame).start();
}catch(Exception e){
e.printStackTrace();
}
}
});
}
public test(){
super();
setBounds(0,0,width,height);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
DrawPanel mainpanel=new DrawPanel();
getContentPane().add(mainpanel,BorderLayout.CENTER);

}
class DrawPanel extends JPanel implements MouseListener,ActionListener{//
final JButton aaa[][]=new JButton[100][100];
public DrawPanel(){
super();
setLayout(null);
setBorder(BorderFactory.createLoweredBevelBorder());
for(int xx=0;xx<main_x;xx++){
for(int yy=0;yy<main_y;yy++){
aaa[xx][yy]=new JButton();
aaa[xx][yy].setBounds(xx*20+5,yy*20+5,20,20);
add(aaa[xx][yy]);
aaa[xx][yy].addActionListener(this);
aaa[xx][yy].addMouseListener(this);
}
}
}
public void paint(Graphics g){
super.paint(g);
Graphics2D g2=(Graphics2D)g;
g2.setColor(Color.GRAY);
g2.setStroke(new BasicStroke(2));
for(int xx=0;xx<main_x;xx++){
for(int yy=0;yy<main_y;yy++){
g2.drawLine(xx*20+5,5,xx*20+5,width-10);
g2.drawLine(5,yy*20+5,height-10,yy*20+5);
}
}
}
public void actionPerformed(ActionEvent e){
remove((JButton)e.getSource());
}
public void mouseClicked(MouseEvent e){
}

public void mouseEntered(MouseEvent e){
}

public void mouseExited(MouseEvent e){
}

public void mousePressed(MouseEvent e){
}

public void mouseReleased(MouseEvent e){
if(e.isPopupTrigger()){
((JButton)e.getSource()).setIcon(sweepicon);
}
}

}
public void run(){
}
}
...全文
365 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pcmlose 2011-02-01
  • 打赏
  • 举报
回复
是啊,谢谢你指导!
zqfddqr 2011-02-01
  • 打赏
  • 举报
回复

public void actionPerformed(ActionEvent e){
remove((JButton)e.getSource());
}


这个 改了

public void actionPerformed(ActionEvent e){
remove((JButton)e.getSource());
this.repaint();
}


这个
this.repaint();
pcmlose 2011-02-01
  • 打赏
  • 举报
回复
发现不止是图片,文字还要按钮的阴影都是这样

按钮是删除了,但按钮上的图片,文字都在
pcmlose 2011-01-31
  • 打赏
  • 举报
回复
原来的按钮是没图片的,为按钮添加图片,然后删除这个按钮,但添加给按钮的图片还在
pcmlose 2011-01-31
  • 打赏
  • 举报
回复
我先为按钮添加图片,然后删除这个按钮,但添加给按钮的图片还在
uastation 2011-01-31
  • 打赏
  • 举报
回复
楼主描述不太明白~

62,610

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧