1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.SwingUtilities;
import java.util.*;
public class DemoMenuItem extends JApplet {
JPanel jPanel1 = new JPanel();
GridLayout gridLayout1 = new GridLayout();
JPanel jPanel2 = new JPanel();
JTabbedPane jTabbedPane1 = new JTabbedPane();
public void init() {
// 1. Get the handle on the applet's content pane.
Container container = this.getContentPane();
// 2. Add a menu bar to the applet.
JMenuBar menuBar = new JMenuBar();
menuBar.setBorder( new BevelBorder(BevelBorder.RAISED) );
menuBar.setBorderPainted(true);
container.add(menuBar, BorderLayout.NORTH);
// 3. Add the File menu and its menu items .
JMenu fileMenu = new JMenu("File", true);
menuBar.add(fileMenu);
// 4. Add the submenus to the File menu.
fileMenu.add(new JMenuItem("New"));
fileMenu.add(new JMenuItem("Open"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Save"));
fileMenu.add(new JMenuItem("Sava As"));
fileMenu.addSeparator();
fileMenu.addSeparator();
// 5. Add the Edit menu and its menu items.
JMenu editMenu = new JMenu("Edit");
menuBar.add(editMenu);
// 6. Add the submenus to the edit menu.
editMenu.add(new JMenuItem("Undo"));
editMenu.addSeparator();
editMenu.add(new JMenuItem("Cut"));
editMenu.add(new JMenuItem("Copy"));
editMenu.add(new JMenuItem("Paste"));
// 7. Create and add the Options menu and submenus
// and their items.
JMenu optionsMenu = new JMenu("Options");
menuBar.add(optionsMenu);
// 8. Add the submenus to the Options menu.
JMenu bookMarksMenu = new JMenu("Book Marks");
optionsMenu.add(bookMarksMenu);
// 9. Add the submenus to the Book Marks menu.
JMenuItem addMI = new JMenuItem("Add Alt-K");
bookMarksMenu.add(addMI);
JMenuItem editMI = new JMenuItem("Edit Alt-B");
bookMarksMenu.add(editMI);
JMenu guideMenu = new JMenu("Guide");
bookMarksMenu.add(guideMenu);
// 10. Add the submenus to the Guide menu.
JMenuItem whatIsNewMI = new JMenuItem("What's New");
whatIsNewMI.setMnemonic('N');
guideMenu.add(whatIsNewMI);
JMenuItem whatIsCoolMI = new JMenuItem("What's Cool");
whatIsCoolMI.setMnemonic('C');
guideMenu.add(whatIsCoolMI);
// 11. Finally, add two more submenus to the Options menu.
JMenuItem javaConsoleMI = new JMenuItem("Java Console");
optionsMenu.add(javaConsoleMI);
JMenuItem addressBookMI = new JMenuItem("Address Book");
optionsMenu.add(addressBookMI);
}
public class DemoTabbedPane extends JApplet {
Container container = null;
private JTabbedPane tabbedPane;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
public void init() {
//1. Get a handle on the applet's content pane.
container = this.getContentPane();
// NOTE: to reduce the amount of code in this example, it uses
// panels with a NULL layout. This is NOT suitable for
// production code since it may not display correctly for
// a given look-and-feel.
JPanel topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel);
// Create the tab pages
createPage1();
createPage2();
createPage3();
// Create a tabbed pane
tabbedPane = new JTabbedPane();
tabbedPane.addTab("Page 1", panel1);
tabbedPane.addTab("Page 2", panel2);
tabbedPane.addTab("Page 3", panel3);
topPanel.add(tabbedPane, BorderLayout.CENTER);
}
public void createPage1() {
panel1 = new JPanel();
panel1.setLayout(null);
JLabel label1 = new JLabel("Username:");
label1.setBounds(10, 15, 150, 20);
panel1.add(label1);
JTextField field = new JTextField();
field.setBounds(10, 35, 150, 20);
panel1.add(field);
JLabel label2 = new JLabel("Password:");
label2.setBounds(10, 60, 150, 20);
panel1.add(label2);
JPasswordField fieldPass = new JPasswordField();
fieldPass.setBounds(10, 80, 150, 20);
panel1.add(fieldPass);
}
public void createPage2() {
panel2 = new JPanel();
panel2.setLayout(new BorderLayout());
panel2.add(new JButton("North"), BorderLayout.NORTH);
panel2.add(new JButton("South"), BorderLayout.SOUTH);
panel2.add(new JButton("East"), BorderLayout.EAST);
panel2.add(new JButton("West"), BorderLayout.WEST);
panel2.add(new JButton("Center"), BorderLayout.CENTER);
}
public void createPage3() {
panel3 = new JPanel();
panel3.setLayout(new GridLayout(3, 2));
panel3.add(new JLabel("Field 1:"));
panel3.add(new TextArea());
panel3.add(new JLabel("Field 2:"));
panel3.add(new TextArea());
panel3.add(new JLabel("Field 3:"));
panel3.add(new TextArea());
}
}
public static void main(String args[]){
JFrame f = new JFrame("PALMYRA FRAMEWORK");
DemoMenuItem demomenuitemApplet = new DemoMenuItem();
// Initialize the applet instance.
demomenuitemApplet.init();
// Add the applet to the JFrame (to it's content pane).
f.getContentPane().add( demomenuitemApplet );
//******************************************************************************************************
//*******************************************************************************************************
// Assign the frame size and display it.
f.setSize(300, 200); // frame: width=300, height = 200
f.show(); // Display the frame
}
public DemoMenuItem() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jPanel1.setLayout(gridLayout1);
this.getContentPane().add(jPanel1, BorderLayout.NORTH);
this.getContentPane().add(jPanel2, BorderLayout.CENTER);
jPanel2.add(jTabbedPane1, null);
}
} |
Partager