跪求用Java 的SWT 做出这个界面 要详细代码,,,跪求大神,, 背景可以不要,,最重要的是两个表格!! 50
展开全部
可以查看下这个类 java.awt.BorderLayout 就是一个布局的问题。 可以分 东西南北中 然后 东西南北中里面可以继续拆分为东西南北中。
给你贴一个例子
package com.tarena.elts.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
/**
* 登录框是具体的窗口框
* LoginFrame(this)
* |--JPanel(BorderLayout) contentPane
* |--(北)JLabel 登录系统
* |--(中)JPanel(BorderLayout) centerPane
* | |--(北)JPanel(GridLayout 2行1列) idPwdPane
* | | |--JPanel(BorderLayout) idPane
* | | | |--(西)JLabel(编号:)
* | | | |--(中)JTextField
* | | |--JPanel(BorderLayout) pwdPane
* | | |--(西)JLable(密码:)
* | | |--(中)JPasswordFiled
* | |--(中)JLabel message
* |--(南)JPanel(FlowLayout)
* |--JButton(登录)
* |--JButton(取消)
*/
public class LoginFrame extends JFrame {
public LoginFrame() {
init();
}
private void init(){//初始化, 初始化界面
this.add(createContentPane());
this.setTitle("登录系统");
this.setSize(280, 200);
this.setLocationRelativeTo(null);//居中
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
clientContext.exit(LoginFrame.this);
}
});
}
private JPanel createContentPane(){//简单工厂方法
JPanel pane = new JPanel(new BorderLayout());
pane.setBorder(new EmptyBorder(10, 10, 10, 10));
pane.add(BorderLayout.NORTH,
new JLabel("登录系统", JLabel.CENTER));
pane.add(BorderLayout.CENTER, createCenterPane());
pane.add(BorderLayout.SOUTH, createButtonPane());
return pane;
}
private JPanel createButtonPane(){
JPanel pane = new JPanel(new FlowLayout());
JButton login = new JButton("Login");
JButton cancel = new JButton("Cancel");
pane.add(login); pane.add(cancel);
//默认回车执行的按钮
getRootPane().setDefaultButton(login);
login.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
//System.out.println("Login Button CLick!");
clientContext.login();
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clientContext.exit(LoginFrame.this);
}
});
return pane;
}
private JPanel createCenterPane(){
JPanel pane = new JPanel(new BorderLayout());
pane.setBorder(new EmptyBorder(8, 0, 0, 0));
pane.add(BorderLayout.NORTH, createIdPwdPane());
//注意
message = new JLabel("", JLabel.CENTER);
message.setForeground(Color.red);
pane.add(BorderLayout.CENTER, message);
return pane;
}
private JPanel createIdPwdPane(){
JPanel pane = new JPanel(new GridLayout(2, 1, 0, 6));
pane.add(createIdPane());
pane.add(createPwdPane());
return pane;
}
private JPanel createIdPane(){
JPanel pane = new JPanel(new BorderLayout());
pane.add(BorderLayout.WEST, new JLabel("编号:"));
//注意!
idField = new JTextField();
pane.add(BorderLayout.CENTER, idField);
return pane;
}
private JPanel createPwdPane(){
JPanel pane = new JPanel(new BorderLayout());
pane.add(BorderLayout.WEST, new JLabel("密码:"));
//注意
pwdField = new JPasswordField();
pwdField.enableInputMethods(true);//处理Linux JVM Bug
pane.add(BorderLayout.CENTER, pwdField);
return pane;
}
private JTextField idField;
private JPasswordField pwdField;
private JLabel message;
private Timer timer = new Timer();
private ClientContext clientContext;
public void setClientContext(ClientContext clientContext) {
this.clientContext = clientContext;
}
public int getUserId(){
return Integer.parseInt(idField.getText());
}
public String getPwd(){
return new String(pwdField.getPassword());
}
public void showMessage(String msg){
message.setText(msg);
timer.schedule(new TimerTask() {
public void run() {
message.setText("");
}
}, 5000);
final Point base = this.getLocation();
final Timer timer2 = new Timer();
timer2.schedule(new TimerTask() {
int i=0;
int[] off = {-5,-3,0,3,5,3,0-3};
public void run() {
setLocation(base.x + off[i++%off.length], base.y);
}
}, 0, 1000/20);
timer2.schedule(new TimerTask() {
public void run() {
timer2.cancel();
setLocation(base);
}
}, 2000);
}
}
更多追问追答
追问
好的,,谢谢,,实际上我的疑问是不知道如何处理那个表格的布局,能给个例子不
追答
表格的布局? 你说的是 此处将语法分析的堆栈过程进行输出 这个地方的表格布局?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询