final project q12 giveup
This commit is contained in:
60
finalproject/Question12/ViewCreate.java
Normal file
60
finalproject/Question12/ViewCreate.java
Normal file
@@ -0,0 +1,60 @@
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class ViewCreate extends View<ControllerCreate> {
|
||||
private JTextField tName;
|
||||
private JTextField tBook;
|
||||
private JComboBox<String> cb;
|
||||
|
||||
public ViewCreate(Library m, ControllerCreate c) {
|
||||
super(m, c);
|
||||
|
||||
// window
|
||||
this.setTitle("View Create");
|
||||
this.setSize(300, 200);
|
||||
|
||||
GridLayout layout = new GridLayout(4, 1);
|
||||
this.setLayout(layout);
|
||||
|
||||
// text field
|
||||
tName = new JTextField();
|
||||
add(tName);
|
||||
|
||||
// text field
|
||||
tBook = new JTextField();
|
||||
add(tBook);
|
||||
|
||||
// box
|
||||
cb = new JComboBox<String>();
|
||||
cb.addItem("Lender");
|
||||
cb.addItem("Borrower");
|
||||
add(cb);
|
||||
|
||||
// button
|
||||
JButton b = new JButton("Create");
|
||||
b.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String name = tName.getText();
|
||||
String num = tBook.getText();
|
||||
String result = c.create(name, num, cb.getSelectedIndex());
|
||||
|
||||
// check
|
||||
if (result != "") {
|
||||
JOptionPane.showMessageDialog(null, result);
|
||||
}
|
||||
}
|
||||
});
|
||||
add(b);
|
||||
|
||||
// final
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user