📄 updateitem.java
字号:
package viewer;
import javax.swing.JTextField;
import java.awt.Rectangle;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import controller.command.*;
import model.persistency.PersistentItem;
import javax.swing.JOptionPane;
import java.awt.Point;
import java.awt.Dimension;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/**
* <p>Title: </p>
* 更新操作框架
* <p>Description: </p>
* 用于更新操作,find按钮用于调出需要更新的题目信息
*/
public class UpdateItem extends OperateFrame{
JLabel jLabel1 = new JLabel();
JTextField timeTextField = new JTextField();
JTextField difTextField = new JTextField();
JTextField anTextField = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField scTextField = new JTextField();
JLabel jLabel3 = new JLabel();
JTextField idTextField = new JTextField();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JButton findButton = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea contentTextArea = new JTextArea();
/**
* constructor
*/
public UpdateItem() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
setSize(new Dimension(525, 440));
setTitle("OLTS System");
jLabel1.setText("Content");
jLabel1.setBounds(new Rectangle(203, 73, 57, 24));
jLabel6.setText("Score");
jLabel6.setBounds(new Rectangle(284, 226, 77, 32));
jLabel5.setText("Time");
jLabel5.setBounds(new Rectangle(22, 300, 64, 29));
jLabel4.setText("Difficulty");
jLabel4.setBounds(new Rectangle(21, 222, 69, 35));
idTextField.setBounds(new Rectangle(58, 65, 118, 30));
jLabel3.setText("ID");
jLabel3.setBounds(new Rectangle(21, 66, 59, 29));
scTextField.setBounds(new Rectangle(351, 225, 118, 30));
jLabel2.setText("Answer");
jLabel2.setBounds(new Rectangle(283, 292, 60, 39));
anTextField.setBounds(new Rectangle(351, 298, 118, 30));
difTextField.setBounds(new Rectangle(117, 226, 118, 30));
timeTextField.setBounds(new Rectangle(117, 298, 118, 30));
findButton.setBounds(new Rectangle(59, 115, 117, 33));
findButton.setText("find");
findButton.addActionListener(new UpdateItem_findButton_actionAdapter(this));
jScrollPane1.setBounds(new Rectangle(277, 62, 192, 116));
this.getContentPane().add(scTextField);
this.getContentPane().add(anTextField);
this.getContentPane().add(difTextField);
this.getContentPane().add(timeTextField);
this.getContentPane().add(jLabel1);
this.getContentPane().add(idTextField);
this.getContentPane().add(jLabel3);
this.getContentPane().add(findButton);
this.getContentPane().add(jScrollPane1);
this.getContentPane().add(jLabel4);
this.getContentPane().add(jLabel5);
this.getContentPane().add(jLabel6);
this.getContentPane().add(jLabel2);
jScrollPane1.getViewport().add(contentTextArea);
super.subButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
trace();}
});
super.submitMenuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
trace();}
});
super.submitButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
trace();}
});
}
/**
* 对find按钮进行处理
* 调用FindCommand,将得到的题目赋给父类的题目属性
* 在相应文本框显示题目信息
* @param e ActionEvent
*/
public void findButton_actionPerformed(ActionEvent e) {
String id = idTextField.getText();
FindCommand fc = new FindCommand(id);
super.t = fc.excute(id);
String dif = super.t.getDifficulty();
String time = new String();
time = time.valueOf(super.t.getTime());
String content = super.t.getContent();
String answer = super.t.getAnswer();
String score = new String();
score = score.valueOf(super.t.getScore());
difTextField.setText(dif);
timeTextField.setText(time);
anTextField.setText(answer);
scTextField.setText(score);
contentTextArea.setText(content);
}
/**
* 对于父类的submit按钮,工具栏中的submit按钮,submit菜单项处理
* 调用UpdateCommand对submit按钮进行处理
* 成功更新后,将各文本框置空
*/
private void trace(){
String id = idTextField.getText();
String difficulty = difTextField.getText();
int time = Integer.parseInt(timeTextField.getText());
String content = contentTextArea.getText();
float score = Float.parseFloat(scTextField.getText());
String answer = anTextField.getText();
super.t = new PersistentItem(1,id,difficulty,time,content,answer,score);
OperateCommand uc = new UpdateCommand(this.t);
uc.excute();
idTextField.setText("");
difTextField.setText("");
timeTextField.setText("");
anTextField.setText("");
scTextField.setText("");
contentTextArea.setText("");
}
}
//////////////////////////////////////////////////////////////////////////////
class UpdateItem_findButton_actionAdapter implements ActionListener {
private UpdateItem adaptee;
UpdateItem_findButton_actionAdapter(UpdateItem adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.findButton_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -