JAVA 中如何禁用JFrame 右上角的叉叉
展开全部
关闭窗口的方法是
如果是Frame窗口 就用下边的代码(不含本代码点击X号没有任何反应)
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0); }
}
);//窗口适配器
如果是JFrame 这用setDefaultCloseOperation(EXIT_ON_CLOSE);//窗口关闭 如果不含本代码点击X号没有任何反应
如果是Frame窗口 就用下边的代码(不含本代码点击X号没有任何反应)
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0); }
}
);//窗口适配器
如果是JFrame 这用setDefaultCloseOperation(EXIT_ON_CLOSE);//窗口关闭 如果不含本代码点击X号没有任何反应
展开全部
JFrame frame;
frame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE);
frame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Frame 修饰的完整示例
import java.awt.*;
import java.awt.event.*;
public class FrameTest {
static Point origin = new Point();
public static void main (String args[]) {
final Frame frame = new Frame();
frame.setUndecorated(true);
frame.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
origin.x = e.getX();
origin.y = e.getY();
}
});
frame.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
Point p = frame.getLocation();
frame.setLocation(
p.x + e.getX() - origin.x,
p.y + e.getY() - origin.y);
}
});
frame.setSize(300, 300);
Button b1 = new Button( "Maximize ");
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
}
});
Button b2 = new Button( "Iconify ");
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Preserve maximizing
frame.setExtendedState(Frame.ICONIFIED
| frame.getExtendedState());
}
});
Button b3 = new Button( "Normal ");
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.setExtendedState(Frame.NORMAL);
}
});
Button b4 = new Button( "Close ");
b4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
frame.setLayout(new GridLayout(5,1));
frame.add(b1);
frame.add(b2);
frame.add(b3);
frame.add(b4);
frame.show();
}
}
import java.awt.*;
import java.awt.event.*;
public class FrameTest {
static Point origin = new Point();
public static void main (String args[]) {
final Frame frame = new Frame();
frame.setUndecorated(true);
frame.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
origin.x = e.getX();
origin.y = e.getY();
}
});
frame.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
Point p = frame.getLocation();
frame.setLocation(
p.x + e.getX() - origin.x,
p.y + e.getY() - origin.y);
}
});
frame.setSize(300, 300);
Button b1 = new Button( "Maximize ");
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
}
});
Button b2 = new Button( "Iconify ");
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Preserve maximizing
frame.setExtendedState(Frame.ICONIFIED
| frame.getExtendedState());
}
});
Button b3 = new Button( "Normal ");
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.setExtendedState(Frame.NORMAL);
}
});
Button b4 = new Button( "Close ");
b4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
frame.setLayout(new GridLayout(5,1));
frame.add(b1);
frame.add(b2);
frame.add(b3);
frame.add(b4);
frame.show();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询