62,610
社区成员
发帖
与我相关
我的任务
分享
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(){
}
}
public void actionPerformed(ActionEvent e){
remove((JButton)e.getSource());
}
public void actionPerformed(ActionEvent e){
remove((JButton)e.getSource());
this.repaint();
}