📄 addnewclass.java
字号:
package frame;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import baseClass.Class;
public class AddNewClass extends JFrame{
public AddNewClass(final ManagerSystem jfram)
{
Container container = getContentPane();
container.setLayout(new GridBagLayout());
final JLabel lblmessage=new JLabel();
JLabel lblId=new JLabel("class id:");
JLabel lblname=new JLabel("class name:");
final JTextArea txtid=new JTextArea();
final JTextArea txtname=new JTextArea();
JButton btnadd=new JButton("add");
btnadd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//if(txtid.getText())
Class tempclass=new Class(txtid.getText(),txtname.getText());
int result=tempclass.addnewClass(tempclass);
switch(result)
{
case 3:
//MessageDialog box=new MessageDialog();
lblmessage.setText("add sucess!");
jfram.myupdate(tempclass.getClassId(),0);
break;
case 2:
lblmessage.setText("class id exist !");
break;
case 1:
lblmessage.setText("class id must be number!");
break;
default:
break;
}
}});
JButton btncancle=new JButton("cancel");
btncancle.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}});
container.add(lblId,new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
container.add(txtid,new GridBagConstraints(1, 0, 5, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
container.add(lblname,new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0));
container.add(txtname,new GridBagConstraints(1, 1, 5, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0));
container.add(btnadd,new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0));
container.add(btncancle,new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0));
container.add(lblmessage,new GridBagConstraints(0, 3, 5, 1, 0.0, 0.0,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
initSizeAndLocation(this,200,200);
//setFrameAlwaysFocus(this);
}
public static void main(String[] args)
{
//new AddNewClass();
}
/**
* Initialize a window of the width and height, and to show it in the middle
* @param window window,maybe JWindow JFrame or JDialog
* @param w width
* @param h height
*/
public static void initSizeAndLocation(Window window, int w, int h) {
window.setSize(w, h);
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
window.setLocation(size.width / 2 - w / 2, size.height / 2 - h / 2);
}
public static void setFrameAlwaysFocus(final JFrame frame) {
new javax.swing.Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
frame.toFront();
}
}).start();
}
public void addresult(int result,JLabel label)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -