Results 1 to 4 of 4
Thread: Opening files using GUI
- 04-24-2011, 09:56 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
Opening files using GUI
I'm working on this assignment for a 'bus company'. I have my main menu as bellow:
which opens my admin menu:Java Code:public class MainMenu { public static void main (String[] args) { JFrame mainMenu = new JFrame ("East Midlands Bus"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); mainMenu.setBounds((int) screenSize.getWidth()/2 - 370, (int) screenSize.getHeight()/2 - 300, 600, 450); // set position and size mainMenu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// exits on close mainMenu.setResizable(false); boolean resizable = mainMenu.isResizable(); Color c = new Color(100,200,255); // set colour of JFrame Container con = mainMenu.getContentPane(); con.setBackground( c ); mainMenu.setLayout(null); JLabel title = new JLabel("East Midlands Bus Route"); // new label title.setBounds(185, 20, 500, 30); // set position and size title.setForeground(Color.BLUE); // set colour of text to blue title.setFont(new Font("Time", Font.BOLD, 18)); // change font and size of text mainMenu.add(title); JLabel bus = new JLabel(new ImageIcon("bus.jpg")); // finds picture bus.setBounds(180, 100, 259, 194); mainMenu.add(bus); JButton price = new JButton("PRICE"); // creates new buttons JButton time = new JButton("TIME"); time.addActionListener(new TimeButtonListener()); JButton route = new JButton("ROUTE"); JButton admin = new JButton("ADMIN"); admin.addActionListener(new AdminButtonListener()); JButton end = new JButton("END"); end.addActionListener(new EndButtonListener()); price.setBounds(45, 100, 90, 30); // sets sizes and locations of buttons time.setBounds(45, 190, 90, 30); route.setBounds(45, 275, 90, 30); admin.setBounds(475, 190, 90, 30); end.setBounds(250, 340, 90, 30); price.setForeground(Color.BLUE); // changes appearence colour of buttons price.setFont(new Font("Time", Font.BOLD, 12)); time.setForeground(Color.BLUE); time.setFont(new Font("Time", Font.BOLD, 12)); route.setForeground(Color.BLUE); route.setFont(new Font("Time", Font.BOLD, 12)); admin.setForeground(Color.BLUE); admin.setFont(new Font("Time", Font.BOLD, 12)); end.setForeground(Color.BLUE); end.setFont(new Font("Time", Font.BOLD, 12)); mainMenu.add(price); // adds buttons mainMenu.add(time); mainMenu.add(route); mainMenu.add(admin); mainMenu.add(end); mainMenu.setVisible(true); // Display the window } } class TimeButtonListener implements ActionListener { TimeButtonListener() {} public void actionPerformed(ActionEvent a) { if (a.getActionCommand().equals("TIME")) { Time_First_Depot x = new Time_First_Depot(); } } } class AdminButtonListener implements ActionListener { AdminButtonListener() {} public void actionPerformed(ActionEvent a) { if (a.getActionCommand().equals("ADMIN")) { Admin x = new Admin(); } } } class EndButtonListener implements ActionListener { EndButtonListener(){} public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("END")) { System.exit(0); } } }
I need to retrieve a route which is saved as a text file using the retrieve button in the admin menu and then open the route using the route button on the main menu but I'm not at all sure as to how to do this at all, and searching the internet hasn't been helpful at all.Java Code:class Admin extends JFrame { Admin() { Container c = getContentPane(); c.setLayout ( null ); Color b = new Color(100,200,255); // set colour of JFrame c.setBackground( b ); JButton input = new JButton("INPUT ROUTE"); // creates new buttons JButton retrieve = new JButton("RETRIEVE ROUTE"); JButton exit = new JButton("EXIT"); JLabel title = new JLabel("Admin"); // new label title.setBounds(270, 20, 500, 30); // set position and size title.setForeground(Color.BLUE); // set colour of text to blue title.setFont(new Font("Time", Font.BOLD, 18)); // change font and size of text c.add(title); JLabel bus = new JLabel(new ImageIcon("bus.jpg")); // finds picture bus.setBounds(180, 100, 259, 194); c.add(bus); JLabel todo = new JLabel("Please select your administration option:"); // new label todo.setBounds(180, 50, 500, 30); // set position and size todo.setForeground(Color.BLUE); // set colour of text to blue todo.setFont(new Font("Time", Font.BOLD, 12)); // change font and size of text c.add(todo); JLabel eastmid = new JLabel("East Midlands Bus"); eastmid.setBounds(250,400,500,30); eastmid.setForeground(Color.BLUE); eastmid.setFont(new Font("Time", Font.BOLD, 12)); c.add(eastmid); input.setForeground(Color.BLUE); // changes appearence colour of buttons input.setFont(new Font("Time", Font.BOLD, 12)); retrieve.setForeground(Color.BLUE); retrieve.setFont(new Font("Time", Font.BOLD, 12)); exit.setForeground(Color.BLUE); exit.setFont(new Font("Time", Font.BOLD, 12)); c.add(input); c.add(retrieve); c.add(exit); input.setBounds(70, 320, 150, 40); retrieve.setBounds(380, 320, 150, 40); exit.setBounds(250, 375, 90, 30); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setBounds((int) screenSize.getWidth()/2 - 370, (int) screenSize.getHeight()/2 - 300, 600, 450); // set position and size this.setResizable(false); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setTitle("Admin"); this.setVisible(true); this.setResizable(false); } }
Thanks in advance for any help that anybody can give.
- 04-24-2011, 11:13 PM #2
- 04-24-2011, 11:39 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
I know that I need an actionlistener but I'm not sure what my if statement would be. I haven't been able to find anything in the Java books I have and online all I've found are command prompt examples not GUI examples.
- 04-25-2011, 12:31 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
opening an URL -
By Sparky in forum New To JavaReplies: 3Last Post: 02-07-2011, 03:58 PM -
Opening files in java
By robby14 in forum Advanced JavaReplies: 11Last Post: 04-19-2010, 03:59 AM -
[HELP]JButton opening a browser and opening a website[HELP]
By Learnin in forum AWT / SwingReplies: 4Last Post: 10-07-2009, 09:14 AM -
Opening Text Files with Default System Editor
By Pesch in forum Advanced JavaReplies: 5Last Post: 10-08-2008, 06:17 PM -
opening jar files on pc prepared by mac
By willemjav in forum Advanced JavaReplies: 42Last Post: 09-27-2008, 05:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks