|
import javax.swing. *; // Insert javax.swing package
import java.awt. *; // Insert java.awt package
import java.awt.event. *; // Insert java.awt.event package
// The following code creates a JFrame frame form
class FrameTest extends JFrame
{
public FrameTest () // Create constructor function
{
super ("Form title"); // Create JFrame class object
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible (true); // Set the form to be visible
setSize (240,100); // Set the window size
}
}
// The following code creates a JPanel panel and adds the panel to the frame form
class PanelTest extends FrameTest
{
JPanel panelObj; // Declare JFrame class object
public PanelTest () // Create constructor function
{
panelObj = new JPanel (); // Create JPanel class object
// panelObj.setBackground (Color.white); // Set the panel color
getContentPane (). add (panelObj); // Add the panel to the form
}
}
// The following code creates a JTable radio button and adds the radio button to the panel
class MenuTest extends PanelTest
{
JMenuBar menuBar;
JMenu menuFile, menuEdit, menuHelp;
JMenuItem menuItemNew, menuItemOpen, menuItemSave;
JMenuItem menuItemCut, menuItemCopy, menuItemPaste;
public MenuTest () // Create constructor function
{
menuBar = new JMenuBar (); // Menu bar JMenuBar
setJMenuBar (menuBar);
menuFile = new JMenu ("FILE (F)"); // Menu JMenu
menuEdit = new JMenu ("Edit (E)");
menuHelp = new JMenu ("Help (H)");
menuBar.add (menuFile);
menuBar.add (menuEdit);
menuBar.add (menuHelp);
menuItemNew = new JMenuItem ("New (N)"); // Menu item JMenuItem
menuItemOpen = new JMenuItem ("Open (O)");
menuItemSave = new JMenuItem ("Save (S)");
menuFile.add (menuItemNew);
menuFile.add (menuItemOpen);
menuFile.add (menuItemSave);
menuItemCut = new JMenuItem ("cut (T)");
menuItemCopy = new JMenuItem ("Copy (C)");
menuItemPaste = new JMenuItem ("Paste (P)");
menuEdit.add (menuItemCut);
menuEdit.add (menuItemCopy);
menuEdit.add (menuItemPaste);
menuEdit.add (menuItemPaste);
}
} |
|