Adding a jToolBar to my desktop application
Hello guys, i have problebs adding a toolbar to my main jframe and i want you to help me. The code is as follows:
import java.io.*;
import javax.swing.*;
import javax.swing.JToolBar;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.Timer;
//import javax.swing.util.*;
//import javax.swing.JPasswordField;
public class UIJBHotelMainGui extends JFrame
{
//ATTRIBUTES
private JButton checkInJButton,checkOutJButton,bookingJButton,view JButton,managementJButton,securityJButton,reportJB utton,logoutJButton;
private Container container;
public UIJBHotelMainGui()
{
super("UIJBHotel");
MainWindowGui();
}
public void MainWindowGui()
{
//Long startTime = System.currentTimeMillis();
JFrame mainFrame = new JFrame("uijbHotel");
mainFrame.setSize(500,400);
mainFrame.setLocation(100,50);
mainFrame.setVisible(true);
JMenuBar mainMenuBar = new JMenuBar();
mainFrame.setJMenuBar(mainMenuBar);
JMenu fileMenu = new JMenu("File");
JMenu helpMenu = new JMenu("Help");
mainMenuBar.add(fileMenu);
mainMenuBar.add(helpMenu);
fileMenu.add(new JMenuItem("Check In"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Check Out"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("View"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Bookin"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Management"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Security"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Report"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Logout"));
fileMenu.addSeparator();
helpMenu.add(new JMenuItem("View Help"));
helpMenu.addSeparator();
helpMenu.add(new JMenuItem("About"));
}//end of mainwindowfui
public static void main (String args[])
{
UIJBHotelMainGui ustaz = new UIJBHotelMainGui();
ustaz.setDefaultCloseOperation(EXIT_ON_CLOSE);
}//end of main
}//end of class UIJBHotelMainGui
Re: Adding a jToolBar to my desktop application
Quote:
Originally Posted by
uijbaba
Hello guys, i have problebs adding a toolbar to my main jframe and i want you to help me.
I think that you will want to tell us what problems you're having, else we have to guess, and we're notoriously bad at doing that.
Quote:
The code is as follows:...
Next time, please use [code=java] [/code] tags so that your posted code is readable. For example:
Code java:
import java.io.*;
import javax.swing.*;
import javax.swing.JToolBar;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.Timer;
//import javax.swing.util.*;
//import javax.swing.JPasswordField;
public class UIJBHotelMainGui extends JFrame
{
//ATTRIBUTES
private JButton checkInJButton,checkOutJButton,bookingJButton,viewJButton,managementJButton,securityJButton,reportJButton,logoutJButton;
private Container container;
public UIJBHotelMainGui()
{
super("UIJBHotel");
MainWindowGui();
}
public void MainWindowGui()
{
//Long startTime = System.currentTimeMillis();
JFrame mainFrame = new JFrame("uijbHotel");
mainFrame.setSize(500,400);
mainFrame.setLocation(100,50);
mainFrame.setVisible(true);
JMenuBar mainMenuBar = new JMenuBar();
mainFrame.setJMenuBar(mainMenuBar);
JMenu fileMenu = new JMenu("File");
JMenu helpMenu = new JMenu("Help");
mainMenuBar.add(fileMenu);
mainMenuBar.add(helpMenu);
fileMenu.add(new JMenuItem("Check In"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Check Out"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("View"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Bookin"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Management"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Security"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Report"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Logout"));
fileMenu.addSeparator();
helpMenu.add(new JMenuItem("View Help"));
helpMenu.addSeparator();
helpMenu.add(new JMenuItem("About"));
}//end of mainwindowfui
public static void main (String args[])
{
UIJBHotelMainGui ustaz = new UIJBHotelMainGui();
ustaz.setDefaultCloseOperation(EXIT_ON_CLOSE);
}//end of main
}//end of class UIJBHotelMainGui
Edit: on review of your code, I don't see anywhere where you've tried to add the JToolBar. It will be hard to guess what you're doing wrong if you don't show us your attempt.
Re: Adding a jToolBar to my desktop application
Quote:
Originally Posted by
curmudgeon
I think that you will want to tell us what problems you're having, else we have to guess, and we're notoriously bad at doing that.
Next time, please use [code=java] [/code] tags so that your posted code is readable. For example:
Code java:
import java.io.*;
import javax.swing.*;
import javax.swing.JToolBar;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.Timer;
//import javax.swing.util.*;
//import javax.swing.JPasswordField;
public class UIJBHotelMainGui extends JFrame
{
//ATTRIBUTES
private JButton checkInJButton,checkOutJButton,bookingJButton,viewJButton,managementJButton,securityJButton,reportJButton,logoutJButton;
private Container container;
public UIJBHotelMainGui()
{
super("UIJBHotel");
MainWindowGui();
}
public void MainWindowGui()
{
//Long startTime = System.currentTimeMillis();
JFrame mainFrame = new JFrame("uijbHotel");
mainFrame.setSize(500,400);
mainFrame.setLocation(100,50);
mainFrame.setVisible(true);
JMenuBar mainMenuBar = new JMenuBar();
mainFrame.setJMenuBar(mainMenuBar);
JMenu fileMenu = new JMenu("File");
JMenu helpMenu = new JMenu("Help");
mainMenuBar.add(fileMenu);
mainMenuBar.add(helpMenu);
fileMenu.add(new JMenuItem("Check In"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Check Out"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("View"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Bookin"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Management"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Security"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Report"));
fileMenu.addSeparator();
fileMenu.add(new JMenuItem("Logout"));
fileMenu.addSeparator();
helpMenu.add(new JMenuItem("View Help"));
helpMenu.addSeparator();
helpMenu.add(new JMenuItem("About"));
}//end of mainwindowfui
public static void main (String args[])
{
UIJBHotelMainGui ustaz = new UIJBHotelMainGui();
ustaz.setDefaultCloseOperation(EXIT_ON_CLOSE);
}//end of main
}//end of class UIJBHotelMainGui
Edit: on review of your code, I don't see anywhere where you've tried to add the JToolBar. It will be hard to guess what you're doing wrong if you don't show us your attempt.
my problem is that i do not know how to add the toolbar given this code. kindly give me some idea so that i will try it and see.
thank you.
Re: Adding a jToolBar to my desktop application
Quote:
Originally Posted by
uijbaba
my problem is that i do not know how to add the toolbar given this code. kindly give me some idea so that i will try it and see.
thank you.
If this were my project, the first place I'd start would be to look at the Swing tutorials: How to use Tool Bars. Please have a look as it contains great explanations and sample code. Learning from these tutorials is an acquired skill, and so the more you do this, the better they'll become for you.