| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1816 人关注过本帖
标题:求大神给看看,图形化界面,运行后窗口是空白,没组件。
只看楼主 加入收藏
相思豆
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-10-25
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:1 
求大神给看看,图形化界面,运行后窗口是空白,没组件。
package lianxi;

import java.awt.BorderLayout;
import java.awt.Color;
import java.
import java.awt.Dimension;
import java.awt.Label;
import java.awt.TextArea;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class MyPaneel extends JFrame {
   
   
    JPanel panelsouth,panelcenter,panelnorth;
    JLabel namelabel,sexlable,shuiguolable,countlabel,advantagelable;
    JButton rewritebutton,querenbutton;
   
    public MyPaneel() {
        // TODO Auto-generated constructor stub
        this.setResizable(false);
        this.setBounds(200, 200, 650,300);
        
        panelnorth=new JPanel();
        this.setLayout(null);
        
        namelabel=new JLabel("你的名字是:");
        namelabel.setBounds(80, 20, 60, 30);
        panelnorth.add(namelabel);
        JTextField TextInput;
        this.add(panelnorth);
        panelnorth.setLayout(null);
        TextInput=new JTextField(10);
        TextInput.setBounds(160, 20,150, 30);
        panelnorth.add(TextInput);
        JLabel sexlabel = new JLabel("性别是:");
        sexlabel.setBounds(160, 20, 60, 30);
        panelnorth.add(sexlabel);
        ButtonGroup buttonGroup=new ButtonGroup();
        JRadioButton manradiobutton =new JRadioButton();
        buttonGroup.add(manradiobutton);
        manradiobutton.setSelected(true);
        manradiobutton.setText("男");
        manradiobutton.setBounds(200, 20, 60, 30);
        panelnorth.add(manradiobutton);
        JRadioButton womanradiobutton =new JRadioButton();
        buttonGroup.add(womanradiobutton);
        womanradiobutton.setSelected(true);
        womanradiobutton.setText("女");
        womanradiobutton.setBounds(300, 20, 60, 30);
        panelnorth.add(womanradiobutton);
        
        panelcenter=new JPanel();
        panelcenter.setLayout(null);
        shuiguolable=new JLabel("你最喜欢的水果是:");
        shuiguolable.setBounds(80, 30, 60, 30);
        panelcenter.add(shuiguolable);
        JCheckBox applecheckbox=new JCheckBox();
        applecheckbox.setText("苹果");
        applecheckbox.setBounds(150, 30, 40, 20);
        panelcenter.add(applecheckbox);
        JCheckBox orangecheckbox=new JCheckBox();
        orangecheckbox.setText("橘子");
        orangecheckbox.setBounds(200, 30, 40, 20);
        panelcenter.add(orangecheckbox);
        JCheckBox bannarcheckbox=new JCheckBox();
        bannarcheckbox.setText("香蕉");
        bannarcheckbox.setBounds(250, 30, 40, 20);
        panelcenter.add(bannarcheckbox);
        JCheckBox peachcheckbox=new JCheckBox();
    peachcheckbox.setText("桃子");
        peachcheckbox.setBounds(300, 30, 40, 20);
        panelcenter.add(peachcheckbox);
        countlabel=new JLabel("你每次吃几个水果");
        countlabel.setBounds(350, 30, 150, 20);
        panelcenter.add(countlabel);
        String[] count={"少于一个","吃一个","吃两个"};
        JComboBox comboBox=new JComboBox(count);
        comboBox.setEditable(true);
        comboBox.setMaximumRowCount(3);
        comboBox.insertItemAt("吃三个", 0);
        comboBox.setSelectedItem("少于一个");
        comboBox.setBounds(510, 30,100 , 30);
        panelcenter.add(comboBox);
        this.add(panelcenter);
        panelsouth=new JPanel();
        panelsouth.setLayout(null);
        advantagelable=new JLabel("你觉得吃水果有什么好处");
        advantagelable.setBounds(300, 60, 200, 30);
        panelsouth.add(advantagelable);
        JTextArea jTextArea=new JTextArea();
        jTextArea.setColumns(15);
        jTextArea.setRows(3);
        jTextArea.setLineWrap(true);
        JScrollPane scrollPane=new JScrollPane();
        scrollPane.setViewportView(jTextArea);
        Dimension dime=jTextArea.getPreferredSize();
        scrollPane.setBounds(100, 100,dime.width,dime.height );
        panelsouth.add(scrollPane);
        querenbutton =new JButton("确定");
        querenbutton.setBounds(400, 100, 70, 30);
        panelsouth.add(querenbutton);
        rewritebutton=new JButton("重写");
        rewritebutton.setBounds(300, 150, 70, 30);
        panelsouth.add(rewritebutton);
        this.add(panelsouth);
        this.setVisible(true);

    }
}

搜索更多相关主题的帖子: package import java 
2016-11-05 15:18
feishi1985
Rank: 2
等 级:论坛游民
帖 子:23
专家分:50
注 册:2011-11-29
收藏
得分:10 
在this.setVisible(true);前面添加 this.pack();
你试一下
2016-11-05 22:49
快速回复:求大神给看看,图形化界面,运行后窗口是空白,没组件。
数据加载中...
 
   



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

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