如何使JFrame窗口的最大化图标不能用?
我在JFrame中用swing画了一个图形,为什么程序运行后没有显示出来,当改变窗口后,才显示? 问题点数:40、回复次数:6Top
1 楼liwenqiu_2001(小秋)回复于 2003-11-03 18:55:39 得分 0
reSize(false)Top
2 楼allen830826($Java)回复于 2003-11-03 19:01:14 得分 10
应该是setResizable(false)Top
3 楼mq612(五斗米)回复于 2003-11-03 19:04:33 得分 10
JFrame frame = new JFrame("...");
frame.setResizable(false);Top
4 楼pangolincn(穿山甲cn)回复于 2003-11-03 19:10:34 得分 0
在JFrame中用JPanel画了一个图形,为什么程序运行后没有显示出来,当改变窗口后,才显示?
这个问题知道吗?
Top
5 楼lwg2019(想成为Java高手)回复于 2003-11-03 19:11:59 得分 20
我给你一个例子!
主程序:
import javax.swing.UIManager;
import java.awt.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Application1 {
boolean packFrame = false;
//Construct the application
public Application1() {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new Application1();
}
}
JFrame:。。。。。。。。。。。。。。
import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame {
JPanel contentPane;
FlowLayout flowLayout1 = new FlowLayout();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
}
catch(Exception e) {
e.printStackTrace();
}
}
public void paint(Graphics g)
{
g.drawString("233",23,34);
g.drawOval(40,60,80,120);
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}Top
6 楼pangolincn(穿山甲cn)回复于 2003-11-03 19:25:26 得分 0
谢谢上面的回答
我还有一个问题
在菜单中我点击完后,菜单就会留在窗口中,怎么才能使菜单点击完后自动消失?Top




