主页的代码:package LUW;importjava.awt.BorderLayout;importjava.awt.FlowLayout;
import java.awt.GridLayout;import java.awt.Image;
import java.awt.event.ActionEvent;import java.awt.event.ActionListener;
import javax.swing.ImageIcon;import javax.swing.JButton;
import javax.swing.JFrame;import javax.swing.JLabel;
import javax.swing.JMenu;import javax.swing.JMenuBar;
import javax.swing.JMenuItem;import javax.swing.JTabbedPane;
public class ShowFlowLayout implements ActionListener {
private ImageRetriever imageretriever = new ImageRetriever();
private LoginUser loginuser=new LoginUser();
private JMenuBar jmenu;
public ShowFlowLayout() {
JFrame frame=new JFrame();
frame.setTitle("Logistics Unlimited Well");
frame.setSize(400, 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
this.jmenu = makeMenubar();
frame.setJMenuBar(jmenu);
frame.add(makeTabbedPane(), BorderLayout.SOUTH);
frame.add(imageretriever.getLogisticsImage());
}
private JMenuBar makeMenubar() {
JMenuBar jmb= new JMenuBar();
JMenu homeMenu= new JMenu("Home");
homeMenu.setMnemonic('M');
jmb.add(homeMenu);
JMenu aboutUsMenu= new JMenu("About Us");
homeMenu.setMnemonic('A');
jmb.add(aboutUsMenu);
JMenuItem companyProfile = new JMenuItem("Company Profile", 'P'); // Create a menu item.
companyProfile.addActionListener(this); aboutUsMenu.add(companyProfile);
JMenuItem servicesAvailable = new JMenuItem("Services Available", 'L'); servicesAvailable.addActionListener(this); servicesMenu.add(servicesAvailable);
JMenuItem howToBook = new JMenuItem("How To Book", 'B'); howToBook.addActionListener(this); customersMenu.add(howToBook);
JMenuItem registerOption = new JMenuItem("Register", 'R'); registerOption.addActionListener(this);
customersMenu.add(registerOption);
JMenuItem visitProducts = new JMenuItem("Visit Products", 'V'); visitProducts.addActionListener(this);
customersMenu.add(visitProducts);
JMenuItem trackOrder = new JMenuItem("Track Order", 'K'); trackOrder.addActionListener(this);
customersMenu.add(trackOrder);
JMenuItem login = new JMenuItem("Login", 'L'); login.addActionListener(this);
transportersMenu.add(login);
JMenuItem transportStatus = new JMenuItem("Transport Status", 'U'); transportStatus.addActionListener(this);
transportersMenu.add(transportStatus);
JMenuItem adequateTransporters = new JMenuItem("Adequate Transporter", 'T'); adequateTransporters.addActionListener(this);
transportersMenu.add(adequateTransporters);
JMenuItem viewProducts = new JMenuItem("View Products", 'V'); viewProducts.addActionListener(this);
suppliersMenu.add(viewProducts);
JMenuItem deliveryStatus = new JMenuItem("Delivery Status", 'D');
deliveryStatus.addActionListener(this);
suppliersMenu.add(deliveryStatus);
JMenuItem adequateSuppliers = new JMenuItem("Adequate Supplier", 'S'); adequateSuppliers.addActionListener(this);
suppliersMenu.add(adequateSuppliers);
JMenuItem orderInformation = new JMenuItem("Order Information", 'I'); orderInformation.addActionListener(this);
ordersMenu.add(orderInformation);
JMenuItem whomToContact = new JMenuItem("Whom To Contact", 'W'); whomToContact.addActionListener(this);
contactsMenu.add(orderInformation);
JMenuItem howToUseLuw = new JMenuItem("How to Use LUW?", 'O'); howToUseLuw.addActionListener(this);
helpMenu.add(howToUseLuw);
return jmb;
}
private JTabbedPane makeTabbedPane() {
JTabbedPane tab = new JTabbedPane();
JButton button = new JButton("Orders");
tab.add("Orders", button);
button = new JButton("Customers");
tab.add("Customers", button);
return tab;
}
public void actionPerformed(ActionEvent e){
loginuser.getUserAccount();
}
public static void main(String[] args) {
new ShowFlowLayout();
}
}login页面:package LUW;
import java.awt.*;import java.awt.event.*;import javax.swing.JFrame;
import javax.swing.JOptionPane;public class LoginUser{
public LoginUser(){
}
public JFrame getUserAccount(){
JFrame f1=new JFrame("LUW 1.0");
final Button b1=new Button("Enter");
final Button b2=new Button("Cancel");
Label l1=new Label("Email");
Label l2=new Label("Password");
final TextField tf1=new TextField(10);
final TextField tf2=new TextField(10);
f1.setSize(200,200);
f1.setBackground(Color.red);
f1.setResizable(false);
f1.setLayout(new FlowLayout());
f1.addWindowListener(new WindowHandler());
tf2.setEchoChar('*');
f1.add(l1);
f1.add(tf1);
f1.add(l2);
f1.add(tf2);
f1.add(b1);
f1.add(b2);
f1.setVisible(true);
return f1;
}}
class WindowHandler extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(1);
}}
import java.awt.GridLayout;import java.awt.Image;
import java.awt.event.ActionEvent;import java.awt.event.ActionListener;
import javax.swing.ImageIcon;import javax.swing.JButton;
import javax.swing.JFrame;import javax.swing.JLabel;
import javax.swing.JMenu;import javax.swing.JMenuBar;
import javax.swing.JMenuItem;import javax.swing.JTabbedPane;
public class ShowFlowLayout implements ActionListener {
private ImageRetriever imageretriever = new ImageRetriever();
private LoginUser loginuser=new LoginUser();
private JMenuBar jmenu;
public ShowFlowLayout() {
JFrame frame=new JFrame();
frame.setTitle("Logistics Unlimited Well");
frame.setSize(400, 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
this.jmenu = makeMenubar();
frame.setJMenuBar(jmenu);
frame.add(makeTabbedPane(), BorderLayout.SOUTH);
frame.add(imageretriever.getLogisticsImage());
}
private JMenuBar makeMenubar() {
JMenuBar jmb= new JMenuBar();
JMenu homeMenu= new JMenu("Home");
homeMenu.setMnemonic('M');
jmb.add(homeMenu);
JMenu aboutUsMenu= new JMenu("About Us");
homeMenu.setMnemonic('A');
jmb.add(aboutUsMenu);
JMenuItem companyProfile = new JMenuItem("Company Profile", 'P'); // Create a menu item.
companyProfile.addActionListener(this); aboutUsMenu.add(companyProfile);
JMenuItem servicesAvailable = new JMenuItem("Services Available", 'L'); servicesAvailable.addActionListener(this); servicesMenu.add(servicesAvailable);
JMenuItem howToBook = new JMenuItem("How To Book", 'B'); howToBook.addActionListener(this); customersMenu.add(howToBook);
JMenuItem registerOption = new JMenuItem("Register", 'R'); registerOption.addActionListener(this);
customersMenu.add(registerOption);
JMenuItem visitProducts = new JMenuItem("Visit Products", 'V'); visitProducts.addActionListener(this);
customersMenu.add(visitProducts);
JMenuItem trackOrder = new JMenuItem("Track Order", 'K'); trackOrder.addActionListener(this);
customersMenu.add(trackOrder);
JMenuItem login = new JMenuItem("Login", 'L'); login.addActionListener(this);
transportersMenu.add(login);
JMenuItem transportStatus = new JMenuItem("Transport Status", 'U'); transportStatus.addActionListener(this);
transportersMenu.add(transportStatus);
JMenuItem adequateTransporters = new JMenuItem("Adequate Transporter", 'T'); adequateTransporters.addActionListener(this);
transportersMenu.add(adequateTransporters);
JMenuItem viewProducts = new JMenuItem("View Products", 'V'); viewProducts.addActionListener(this);
suppliersMenu.add(viewProducts);
JMenuItem deliveryStatus = new JMenuItem("Delivery Status", 'D');
deliveryStatus.addActionListener(this);
suppliersMenu.add(deliveryStatus);
JMenuItem adequateSuppliers = new JMenuItem("Adequate Supplier", 'S'); adequateSuppliers.addActionListener(this);
suppliersMenu.add(adequateSuppliers);
JMenuItem orderInformation = new JMenuItem("Order Information", 'I'); orderInformation.addActionListener(this);
ordersMenu.add(orderInformation);
JMenuItem whomToContact = new JMenuItem("Whom To Contact", 'W'); whomToContact.addActionListener(this);
contactsMenu.add(orderInformation);
JMenuItem howToUseLuw = new JMenuItem("How to Use LUW?", 'O'); howToUseLuw.addActionListener(this);
helpMenu.add(howToUseLuw);
return jmb;
}
private JTabbedPane makeTabbedPane() {
JTabbedPane tab = new JTabbedPane();
JButton button = new JButton("Orders");
tab.add("Orders", button);
button = new JButton("Customers");
tab.add("Customers", button);
return tab;
}
public void actionPerformed(ActionEvent e){
loginuser.getUserAccount();
}
public static void main(String[] args) {
new ShowFlowLayout();
}
}login页面:package LUW;
import java.awt.*;import java.awt.event.*;import javax.swing.JFrame;
import javax.swing.JOptionPane;public class LoginUser{
public LoginUser(){
}
public JFrame getUserAccount(){
JFrame f1=new JFrame("LUW 1.0");
final Button b1=new Button("Enter");
final Button b2=new Button("Cancel");
Label l1=new Label("Email");
Label l2=new Label("Password");
final TextField tf1=new TextField(10);
final TextField tf2=new TextField(10);
f1.setSize(200,200);
f1.setBackground(Color.red);
f1.setResizable(false);
f1.setLayout(new FlowLayout());
f1.addWindowListener(new WindowHandler());
tf2.setEchoChar('*');
f1.add(l1);
f1.add(tf1);
f1.add(l2);
f1.add(tf2);
f1.add(b1);
f1.add(b2);
f1.setVisible(true);
return f1;
}}
class WindowHandler extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(1);
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货