我必须创建一个用于借出媒体项目的库。到目前为止,我有GUI来查看它应该如何,但现在我已经打了一个砖墙,接下来该做什么。当用户点击“添加”按钮时按钮,两个提示应该打开询问用户标题然后格式,但我不知道该怎么做才能实现它。任何帮助都会很棒!
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
public class FinalView extends JFrame{
private JButton add;
private JButton checkOut;
private JButton checkIn;
private JButton delete;
private JScrollPane display;
private JList jlist;
Scanner input = new Scanner(System.in);
public FinalView(){
setTitle("My Library");
setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//change later for save feature per printout
setLocationRelativeTo(null);
setLayout(new BorderLayout());
JPanel buttonPanel = new JPanel();
add(buttonPanel, BorderLayout.SOUTH);
buttonPanel.setLayout(new GridLayout(1, 4, 8, 8));
add = new JButton("Add");
checkOut = new JButton("Check Out");
checkIn = new JButton("Check In");
delete = new JButton("Delete");
buttonPanel.add(add);
buttonPanel.add(checkOut);
buttonPanel.add(checkIn);
buttonPanel.add(delete);
String[] movie = {"Star Wars", "StarTrek"};
Library call = new Library();
jlist = new JList(movie);
jlist.setVisibleRowCount(4);
jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
add(new JScrollPane(jlist));
setVisible(true);
ActionListener listener = null;
add.addActionListener(listener);
}
public void actionPerformed(ActionEvent e) {
JOptionPane.showInputDialog("Title:");
String title = input.nextLine();
JOptionPane.showInputDialog("Format:");
String format = input.nextLine();
addNewItem(title, format);
}
private void addNewItem(String title, String format) {
MediaItem lib = new MediaItem(title, format);
// TODO Auto-generated method stub
}
public static void main(String[] args) {
new FinalView();
}
}