📄 mybuttonframe.java
字号:
package mybutton;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.event.*;
/**
* <p>Title: mybutton</p>
* <p>Description: This is a text for mouseevent</p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class MyButtonFrame extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
public class MyButton extends JButton {
private MyButton friend=null;
public MyButton(){}
public MyButton(String title) {
super(title);
enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
}
public void setFiend(MyButton friend){
this.friend=friend;
}
protected void processMouseMotionEvent(MouseEvent e){
setVisible(false);
friend.setVisible(true);
}
}
MyButton jButton1 = new MyButton();
MyButton jButton2 = new MyButton();
//Construct the frame
public MyButtonFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setText("Can you catch me?");
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("MyButton");
jButton2.setText("Can you catch me?");
contentPane.add(jButton1, BorderLayout.NORTH);
contentPane.add(jButton2, BorderLayout.SOUTH);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -