如何使JFrame窗口的最大化图标不能用?

pangolincn 2003-11-03 06:39:03
我在JFrame中用swing画了一个图形,为什么程序运行后没有显示出来,当改变窗口后,才显示?
...全文
259 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pangolincn 2003-11-03
  • 打赏
  • 举报
回复
谢谢上面的回答
我还有一个问题
在菜单中我点击完后,菜单就会留在窗口中,怎么才能使菜单点击完后自动消失?
lwg2019 2003-11-03
  • 打赏
  • 举报
回复
我给你一个例子!
主程序:
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);
}
}



}
pangolincn 2003-11-03
  • 打赏
  • 举报
回复

在JFrame中用JPanel画了一个图形,为什么程序运行后没有显示出来,当改变窗口后,才显示?
这个问题知道吗?
mq612 2003-11-03
  • 打赏
  • 举报
回复
JFrame frame = new JFrame("...");
frame.setResizable(false);
allen830826 2003-11-03
  • 打赏
  • 举报
回复
应该是setResizable(false)
liwenqiu_2001 2003-11-03
  • 打赏
  • 举报
回复
reSize(false)

62,629

社区成员

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

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