一个小桌面的java代码 java桌面gui

java: 创建一个桌子Table类 , 该类中有桌子名称,重量,桌面宽度,长度及桌子高度属性 。public class Table {
// 名称
private String name;
// 重量
private float weight;
// 宽度
private float width;
// 高度
private float height;
// 长度
private float length;
public Table() {
}
// 带4个参数的构造方法初始化所有数据成员
public Table(float weight, float width, float height, float length) {
super();
if (weight0 || height0 || width0 || length0) {
System.out.println("桌子的重量,宽度、长度和高度初始化时不能为负数");
} else {
this.weight = weight;
this.width = width;
this.height = height;
this.length = length;
}
}
// 计算桌面面积
public int area() {
return (int) (this.length * this.width);
}
public void display() {
System.out.println("名字:" + name + ";桌面长度:" + length + ";桌面宽度:" + width
+ ";重量:" + weight+";高度:"+height);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
if (weight0) {
System.out.println("桌子的重量不能为负数");
} else {
this.weight = weight;
}
}
public float getWidth() {
return width;
}
public void setWidth(float width) {
if (width0) {
System.out.println("桌子的宽度不能为负数");
} else {
this.width = width;
}
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
if (height0) {
System.out.println("桌子的高度不能为负数");
} else {
this.height = height;
}
}
public float getLength() {
return length;
}
public void setLength(float length) {
if (height0) {
System.out.println("桌子的长度不能为负数");
} else {
this.length = length;
}
}
}
另外 5个属性4个参数 初始化全部不能理解
求一个简单的java代码:(图形界面)import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class vv extends JDialog {
private static final long serialVersionUID = 1L;
private JLabel l_Id = new JLabel("登陆账户", JLabel.CENTER);
private JLabel l_pw = new JLabel("登陆密码", JLabel.CENTER);
private JTextField t_Id = new JTextField(10);
private JPasswordField t_pw = new JPasswordField(10);
private JButton btnLogin;
private JButton btnClose;
public vv() {
super();
setResizable(false);
getContentPane().setBackground(new Color(225, 225, 225));
getContentPane().setLayout(null);
initialize();
}
protected void initialize() {
setTitle("系统登录");
l_Id.setBounds(48, 43, 53, 25);
t_Id.setBounds(110, 43, 150, 25);
l_pw.setBounds(48, 93, 53, 25);
t_pw.setBounds(110, 93, 150, 25);
getContentPane().add(l_Id);
getContentPane().add(l_pw);
getContentPane().add(t_Id);
getContentPane().add(t_pw);
btnLogin = new JButton();
btnLogin.setText("登录");
btnLogin.setBounds(70, 142, 85, 28);
btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

推荐阅读