这个JAVA程序怎么让他堆满整个屏幕啊

importjavax.swing.JFrame;importjavax.swing.JTextArea;publicclassaaa{/***@paramargs*@t... import javax.swing.JFrame;
import javax.swing.JTextArea;

public class aaa {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
int x = 0;
int y = 0;
for (int i = 0; i < 20; i++) {
JFrame frame = new JFrame();

JTextArea area = new JTextArea("welcom to textarea!");
area.setText("lol");
frame.add(area);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setLayout(new FlowLayout());
frame.setVisible(true);
x= x+200;

frame.setBounds(x , y , 300 , 100);
Thread.sleep(100);
}

}
}
展开
 我来答
老僧中0
2017-06-25 · TA获得超过2535个赞
知道小有建树答主
回答量:2995
采纳率:12%
帮助的人:790万
展开全部
获取屏幕的长度和高度,然后在location 方法里进行设置边界是它们的一半就可以了,下面的getMidDimesion方法就是这样。
例子:
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class testFrame extends Frame
{
public testFrame(int width,int height)
{
this.setSize( width,height);
this.setLocation(testFrame.getMidDimesion( new Dimension(width,height)));
this.setBackground( Color.BLACK );
this.setVisible( true);
this.addWindowListener(new WindowListener()
{
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
System.exit(0);
}
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
获取屏幕的长度和高度,然后在location 方法里进行设置边界是它们的一半就可以了,下面的getMidDimesion方法就是这样。
例子:
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class testFrame extends Frame
{
public testFrame(int width,int height)
{
this.setSize( width,height);
this.setLocation(testFrame.getMidDimesion( new Dimension(width,height)));
this.setBackground( Color.BLACK );
this.setVisible( true);
this.addWindowListener(new WindowListener()
{
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
System.exit(0);
}
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
});
}
public static Point getMidDimesion(Dimension d)
{
Point p = new Point();
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
p.setLocation((dim.width - d.width)/2,(dim.height - d.height)/2);
return p;
}
public static void main(String[] args)
{
new testFrame(300,200);
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式