如何使JFrame窗口的最大化图标不能用? JFrame frame = new JFrame("...");frame.setResizable(false); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在JFrame中用JPanel画了一个图形,为什么程序运行后没有显示出来,当改变窗口后,才显示?这个问题知道吗? 我给你一个例子!主程序: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); } }} 怎么样不基于开发软件运行java? 本地文件索引的菜鸟问题 关java +电子收银系统问题中的一段代码 JAVA FTP客户端 怎么老是连不上服务器 菜鸟问题 请各位帮个忙,谢谢! java中能否识别中文目录或读取中文命名的文件? 进程中的JAVAW是什么意思? 为什么会出错呢?希望各位大侠们仗义!!! 求分享java学习经验。。。。。。。。 applet 简单问题,在线所求答案。 用appletviewer运行一个APPLET程序,能够做一个关闭按钮然后点击这个按钮关闭applet窗体吗?
在JFrame中用JPanel画了一个图形,为什么程序运行后没有显示出来,当改变窗口后,才显示?
这个问题知道吗?
主程序:
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);
}
}}