Hi,
I can't seem to understand how to fill the frame within my window.
I understand how to create menus, items, ActionListener and all that stuff, but I'm at a loss when trying to make use of the frame itself. Exemples I fall upon are all about creating a window and its frame, without any menu, and I can't seem to use both those things.
Here's my basic code, if someone would be so nice as to point out how to make use of my frame, it would be greatly appreciated. I plan to use a JSplitPane, filled with textpanes, but i'm sure I'll be able to figure it out on my own once I know how to use the frame for a simple TextFrame.
import javax.swing.*; import java.awt.event.*; public class LaFenetre extends JFrame implements ActionListener { static final long serialVersionUID = 0L; //Event declarations static final String File_Quit = "Quit"; //Constructor public LaFenetre() { super ("CheckTradeOrders"); // Application closes when window is shut. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Initialize window Initialize(); } private void Initialize() { //MenuBar creation JMenuBar menuBar; menuBar = new JMenuBar(); //Menus creation JMenu menuFile; //File Menu creation menuFile = new JMenu("File"); menuFile.setMnemonic(KeyEvent.VK_F); menuFile.getAccessibleContext().setAccessibleDescription("File menu"); menuBar.add(menuFile); //Quit command creation JMenuItem mnItemQuit = new JMenuItem(File_Quit); mnItemQuit.setMnemonic(KeyEvent.VK_Q); mnItemQuit.getAccessibleContext().setAccessibleDescription("Quit program"); mnItemQuit.addActionListener(this); menuFile.add(mnItemQuit); // adding menu bar to window setJMenuBar(menuBar); setSize(800,600); } // Event handler public void actionPerformed(ActionEvent evt) { String action = evt.getActionCommand(); if (action==File_Quit) { System.exit(0); } } static public void main(String[] args) { JFrame f = new LaFenetre(); f.setVisible(true); } }
Thanks