当前位置:编程学习 > JAVA >>

关于java图形界面的小问题 求大神解答。初学者





想要编辑这样一个简单的 图形界面 用最基本的 代码编写 初学、 谢谢了。 关于java图形界面的小问题 --------------------编程问答-------------------- 先学基本的布局,和一些基本控件,然后自己就可以写了. --------------------编程问答-------------------- 我想要代码。 --------------------编程问答--------------------



package test01;

import java.awt.*;
import javax.swing.*;


public class FileCloseDemo extends JFrame {

/**
 * 
 */
private static final long serialVersionUID = 3119601964560046270L;
/* ***左1*** */
private JRadioButton open = null;
private JRadioButton save = null;
private JRadioButton custom = null;
private JTextArea dialog1 = null;
/* ***左2*** */
private JButton remove = null;
private JButton addall = null;
private JRadioButton def = null;
private JRadioButton addjpg = null;
/* ***左3*** */
private JCheckBox box1=null;
private JCheckBox box2=null;
private JCheckBox box3=null;
private JCheckBox box4=null;
private JCheckBox box5=null;
/* ***左4*** */
private JRadioButton rb1=null;
private JRadioButton rb2=null;
private JRadioButton rb3=null;
private JRadioButton rb4=null;
private JRadioButton rb5=null;
/* ***下*** */
private JRadioButton metal = null;
private JRadioButton motif = null;
private JRadioButton windows = null;
private JButton FileChoooser = null;

public static void main(String[] args) {
// TODO Auto-generated method stub
new FileCloseDemo();
}

FileCloseDemo() {

this.setLayout(new BorderLayout());
JPanel center = new JPanel(new GridLayout(1, 4));
// JPanel center = new JPanel();
// center.setLayout(new BoxLayout(center, BoxLayout.X_AXIS));
/* ***左1*** */
center.add(getDialogType());
/* ***左2*** */
center.add(getFilterControls());
/* ***左3*** */
center.add(getDisplayOptions());
/* ***左4*** */
center.add(getFileAndDirectory());
this.add(center, BorderLayout.CENTER);
/* ***下*** */
this.add(getBottom(), BorderLayout.SOUTH);

Initialization();
}

/***
 * 初始化窗体
 */
private void Initialization() {

this.setTitle("FileCloseDemo");
this.setSize(700, 300);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}

private JPanel getDialogType() {

JPanel dialog = new JPanelBox("DialogType");
/* 设置布局格式 这里用的是Y型的,也可以使用 GridLayout 4行1列 也可以用其他布局实现 */
dialog.setLayout(new BoxLayout(dialog, BoxLayout.Y_AXIS));

open = new JRadioButton("Open");
save = new JRadioButton("Save");
custom = new JRadioButton("Custom");
dialog1 = new JTextArea("Dialog1");
/* 创建一个按钮容器,使得各个RadioButton互斥 */
ButtonGroup group = new ButtonGroup();
group.add(open);
group.add(save);
group.add(custom);

dialog.add(open);
dialog.add(save);
dialog.add(custom);
dialog.add(dialog1);

return dialog;
}

private JPanel getFilterControls() {
JPanel Filter = new JPanelBox(new GridLayout(4,1,10,10),"FilterControls");
//Filter.setLayout(new BoxLayout(Filter, BoxLayout.Y_AXIS));
//Filter.setLayout(new BorderLayout(1,4));

remove = new JButton("Remove\"All Files\"Filer");
addall = new JButton("Add\"All Files\"Filer");
def = new JRadioButton("Defalut Filering");
addjpg =  new JRadioButton("Add JPG and GIF Filters");
ButtonGroup group = new ButtonGroup();
group.add(def);
group.add(addjpg);

Filter.add(remove);
Filter.add(addall);
Filter.add(def);
Filter.add(addjpg);


return Filter;
}

private JPanel getDisplayOptions() {
JPanel Display = new JPanelBox(new GridLayout(5,1),"DisplayOptions");
//JPanel Display = new JPanelBox("DisplayOptions");
//Display.setLayout(new BoxLayout(Display, BoxLayout.Y_AXIS));
box1 = new JCheckBox("Show Hidden Files");
box2 = new JCheckBox("Show Extensions");
box3 = new JCheckBox("Show FileView");
box4 = new JCheckBox("Show PreView");
box5 = new JCheckBox("Show Control Buttons");
Display.add(box1);
Display.add(box2);
Display.add(box3);
Display.add(box4);
Display.add(box5);

return Display;
}

private JPanel getFileAndDirectory() {
JPanel FileAndDirectory =  new JPanelBox(new GridLayout(5,1),"FileAndDirectory");
// JPanel FileAndDirectory = new JPanelBox("FileAndDirectory");
// FileAndDirectory.setLayout(new BoxLayout(FileAndDirectory,BoxLayout.Y_AXIS));

rb1 = new JRadioButton("Just Select Files");
rb2 = new JRadioButton("Just Select Directories");
rb3 = new JRadioButton( "<html><p>Select Files or </p></p>Directories</p></html>");

rb4 = new JRadioButton("Single Selection");
rb5 = new JRadioButton("Multi Selection");
ButtonGroup group = new ButtonGroup();
group.add(rb1);
group.add(rb2);
group.add(rb3);
group.add(rb4);
group.add(rb5);

FileAndDirectory.add(rb1);
FileAndDirectory.add(rb2);
FileAndDirectory.add(rb3);
FileAndDirectory.add(rb4);
FileAndDirectory.add(rb5);


return FileAndDirectory;
}

private JPanel getBottom() {
JPanel Bottom = new JPanelBox(new FlowLayout(), "");

metal = new JRadioButton("Metal");
motif = new JRadioButton("Motif");
windows = new JRadioButton("Windows");
FileChoooser = new JButton("FileChoooser");

ButtonGroup group = new ButtonGroup();
group.add(metal);
group.add(motif);
group.add(windows);

Bottom.add(metal);
Bottom.add(motif);
Bottom.add(windows);
Bottom.add(FileChoooser);
return Bottom;
}
}






package test01;


import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.LayoutManager;
 
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
 
public class JPanelBox extends JPanel {
 
    /**
     *
     */
    private static final long serialVersionUID = 1L;
 
    /**
     * @param 自定义一个带有边框的JPanel扩展类
     */
    // 容器 标题
    public JPanelBox(String title) {
       setTitledBorder(title);
    }
    // 容器 标题
    public JPanelBox(Component comp, String title) {
       super(new BorderLayout());
       add(BorderLayout.CENTER, comp);
       setTitledBorder(title);
    }
 
    // 布局类型 标题
    public JPanelBox(LayoutManager layou, String title) {
       super(layou);
       setTitledBorder(title);
    }
 
    // 设置标题
    private void setTitledBorder(String title) {
       //边框
       EtchedBorder etched = new EtchedBorder(EtchedBorder.LOWERED);
       TitledBorder titled = new TitledBorder(etched, title);
       super.setBorder(titled);
    }
}


--------------------编程问答-------------------- --------------------编程问答-------------------- 这怎么不能使用  /*   */ 注释?
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,