我有一个小程序已经启动了多个菜单项。
单击一个项目时,我希望在框架上显示一些内容,当单击另一个项目时,第一个项目消失,第二个出现。
我可以打印到控制台,但似乎无法打印到框架。
任何建议,将不胜感激:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class melco extends JFrame{
public static void main(String[] args){
JFrame frame = new JFrame("Salesman Resources");
frame.setVisible(true);
frame.setSize(1000,800);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menubar = new JMenuBar();
frame.setJMenuBar(menubar);
JMenu file = new JMenu("File");
menubar.add(file);
JMenuItem exit = new JMenuItem("Exit");
file.add(exit);
JMenu orders = new JMenu("Orders");
menubar.add(orders);
JMenuItem bookedorders = new JMenuItem("Booked Orders");
orders.add(bookedorders);
JMenuItem backorders = new JMenuItem("BackOrders");
orders.add(backorders);
JMenu customers = new JMenu("Customers");
menubar.add(customers);
JMenuItem customersales = new JMenuItem("Customer Sales");
customers.add(customersales);
JMenuItem customeritems = new JMenuItem("Customer Items");
customers.add(customeritems);
JMenuItem customerprices = new JMenuItem("Customer Prices");
customers.add(customerprices);
JMenuItem customerlistings = new JMenuItem("Customer Listings");
customers.add(customerlistings);
JMenu inv = new JMenu("INV");
menubar.add(inv);
JMenuItem surplusinv = new JMenuItem("Surplus Inv");
inv.add(surplusinv);
JMenuItem stockinv = new JMenuItem("Stock Inv");
inv.add(stockinv);
JMenu search = new JMenu("Searh");
menubar.add(search);
JMenuItem itemsearch = new JMenuItem("Item Search");
search.add(itemsearch);
JMenuItem customersearch = new JMenuItem("Customer Search");
search.add(customersearch);
JMenu menulostsales = new JMenu("Lost Sales");
menubar.add(menulostsales);
JMenuItem lostsales = new JMenuItem("Lost Sales");
menulostsales.add(lostsales);
JMenu menumarginadvisor = new JMenu("Margin Advisor");
menubar.add(menumarginadvisor);
JMenuItem marginadvisor = new JMenuItem("Margin Advisor");
menumarginadvisor.add(marginadvisor);
JMenu menumakeandhold = new JMenu("Make and Hold");
menubar.add(menumakeandhold);
JMenuItem makeandhold = new JMenuItem("Make and Hold");
menumakeandhold.add(makeandhold);
makeandhold.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e)
{
System.out.println("Make and Hold is pressed");
System.out.println("Hello World");
// This is Make and Hold Area
}
}
);
class exitaction implements ActionListener {
public void actionPerformed (ActionEvent e){
System.exit(0);
}
}
exit.addActionListener(new exitaction());
}
}