运行通过了,庆祝一下!
//SUN对象篇divelog例子
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog{
public DiveLog(){
dlframe = new JFrame("A Java(TM) Technology Dive Log");
// Creates a frame object to add to
// the application GUI components.
// Closes from title bar
// and from menu
dlframe.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
// Tabbed pane with panels for Jcomponents
// Instantiate JTabbedPane with keyword new
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
// Calls method to set color
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
populateTabbedPane();
buildMenu();
dlframe.getContentPane().add(tabbedPane);
dlframe.pack();
dlframe.setSize(765, 690);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
}
private JFrame dlframe; //Not assigned yet.
private JTabbedPane tabbedPane; //Not assigned yet.
private void populateTabbedPane(){
// Create tabs with titles
tabbedPane.addTab("Welcome", null, new Welcome(),
"Welcome to the Dive Log");
tabbedPane.addTab("Diver Data", null, new Diver(),
"Click here to enter diver data");
tabbedPane.addTab("Log Dives", null, new Dives(),
"Click here to enter dives");
tabbedPane.addTab("Statistics", null, new Statistics(),
"Click here to calculate" + " dive statistics");
tabbedPane.addTab("Favorite Web Site", null, new WebSite(),
"Click here to see a web site");
tabbedPane.addTab("Resources", null, new Resources(),
"Click here to see a list " +"of resources");
} //Ends populateTabbedPane method
// Method header
private void buildMenu(){
// Instantiates JMenuBar, JMenu,
// and JMenuItem.
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//Adds the item to the menu object
menu.add(item);
//Adds the menu object with item
//onto the menu bar
mb.add(menu);
//Sets the menu bar in the frame
dlframe.setJMenuBar(mb);
//Closes the application from the Exit
//menu item.
item.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});// Ends buildMenu method
}
public static void main(String[] args){
DiveLog dl = new DiveLog();
}
}
有点灌水的嫌疑……
页:
[1]