| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 891 人关注过本帖
标题:[求助]BoxLayout布局问题
只看楼主 加入收藏
xbw0114
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2007-8-8
收藏
 问题点数:0 回复次数:5 
[求助]BoxLayout布局问题

import java.awt.Frame;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class BoxLayoutDemo extends JFrame {

private static final long serialVersionUID = 1L;
private JButton jButton1 = null;
private JButton jButton = null;
private JButton jButton3 = null;


public BoxLayoutDemo() {
super();
try{
initialize();
}
catch (Exception e){
e.printStackTrace();
}
}
private void initialize() throws Exception {
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.setSize(300, 200);
this.setTitle("Frame");

this.add(getJButton1(), null);
this.add(getJButton(), null);
this.add(getJButton3(), null);

}
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("JButton1");
}
return jButton1;
}
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("JButton2");
}
return jButton;
}
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setText("JButton3");
}
return jButton3;}

public static void main (String[] args){
try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

}catch (Exception e)
{
e.printStackTrace();
}
BoxLayoutDemo frame =new BoxLayoutDemo();
frame.setVisible(true);
}
protected void processWindowEvent(WindowEvent e)
{
if(e.getID()==WindowEvent.WINDOW_CLOSING)
System.exit(0);
}
}
程序有什么错误吗?为什么运行不出来呀?

[此贴子已经被作者于2007-8-29 0:31:34编辑过]

搜索更多相关主题的帖子: import BoxLayout awt java JButton 
2007-08-29 00:17
xbw0114
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2007-8-8
收藏
得分:0 

谁能帮帮忙吗?急


勤奋造就未来
2007-08-29 10:43
george_vcool
Rank: 2
等 级:新手上路
威 望:3
帖 子:453
专家分:0
注 册:2007-7-23
收藏
得分:0 

import java.awt.Frame;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class BoxLayoutDemo extends JFrame {

private static final long serialVersionUID = 1L;
private JButton jButton1 = null;
private JButton jButton = null;
private JButton jButton3 = null;


public BoxLayoutDemo() {
super();
try{
initialize();
}
catch (Exception e){
e.printStackTrace();
}
}
private void initialize() throws Exception {
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));//改成this.getContentPane()
this.setSize(300, 200);
this.setTitle("Frame");

this.add(getJButton1(), null);//改成this.getContentPane()
this.add(getJButton(), null);/改成this.getContentPane()
this.add(getJButton3(), null);改成this.getContentPane()

}
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("JButton1");
}
return jButton1;
}
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("JButton2");
}
return jButton;
}
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setText("JButton3");
}
return jButton3;}

public static void main (String[] args){
try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

}catch (Exception e)
{
e.printStackTrace();
}
BoxLayoutDemo frame =new BoxLayoutDemo();
frame.setVisible(true);
}
protected void processWindowEvent(WindowEvent e)
{
if(e.getID()==WindowEvent.WINDOW_CLOSING)
System.exit(0);
}

2007-08-29 19:13
xbw0114
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2007-8-8
收藏
得分:0 

能问下为什么要这样改呀?


勤奋造就未来
2007-08-29 20:11
george_vcool
Rank: 2
等 级:新手上路
威 望:3
帖 子:453
专家分:0
注 册:2007-7-23
收藏
得分:0 

应该说是语法吧!!
这个布局管理器应该这么用!

2007-08-29 20:55
xbw0114
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2007-8-8
收藏
得分:0 

多谢咯


勤奋造就未来
2007-08-29 22:45
快速回复:[求助]BoxLayout布局问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036648 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved