![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2006
Location: Rochester, NY
Posts: 18
Rep Power: 0
![]() |
Java CS Project
I have to do this project for CS2. I'm not too excited, but I'll post the code when I finish it if anyone's interested. I'll definitely have it done by Sunday.
|
|
|
|
|
|
#2 |
|
Expert Programmer
|
That's a lot of work for one weekend.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Feb 2006
Location: Rochester, NY
Posts: 18
Rep Power: 0
![]() |
Not at all. It will take 5-8 hours max. Gui's aren't that hard to make in java.
|
|
|
|
|
|
#4 |
|
Sexy Programmer
|
Hey! I am definitly! Looks rather exciting to create something like that!
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Feb 2006
Location: Rochester, NY
Posts: 18
Rep Power: 0
![]() |
Alright, I've spent almost 2 hours on it and here's the main GUI
[HTML] /** * Hotel.java * * A program designed to reserve rooms during 2006 for a basic hotel */ /** * @author John Watts * */ import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.border.Border; public class Hotel extends JPanel implements WindowListener, ActionListener{ static JFrame frame; JPanel welcome, rates, availability; JLabel ratesLabel,welcomeLabel,textLabel; Border titledBorder; public Hotel(){ super(new BorderLayout()); frame.getContentPane().add(this); frame.addWindowListener(this); //~North Panel welcome = new JPanel(new FlowLayout(1)); welcome.setBackground(Color.WHITE); this.add(welcome, BorderLayout.NORTH); welcomeLabel = new JLabel("Welcome to the Hotel Reservation System"); welcome.add(welcomeLabel); //~End North Panel //~West Panel rates = new JPanel(new GridLayout(10,1)); rates.setBackground(Color.YELLOW); this.add(rates, BorderLayout.WEST); ratesLabel = new JLabel("Rates for 2006:"); rates.add(ratesLabel); ratesLabel = new JLabel(" "); rates.add(ratesLabel); ratesLabel = new JLabel("Single Room: $100"); rates.add(ratesLabel); ratesLabel = new JLabel("Double Room: $125"); rates.add(ratesLabel); ratesLabel = new JLabel("King Room: $150"); rates.add(ratesLabel); ratesLabel = new JLabel(" "); rates.add(ratesLabel); ratesLabel = new JLabel("Rates given are per night,"); rates.add(ratesLabel); ratesLabel = new JLabel("smoking or non-smoking"); rates.add(ratesLabel); ratesLabel = new JLabel(" "); rates.add(ratesLabel); ratesLabel = new JLabel(" "); rates.add(ratesLabel); //~End West Panel //Center Panel Border availabilityBorder = BorderFactory.createTitledBorder( "Check Availability"); JPanel availability = new JPanel(new GridLayout(5,1)); availability.setBackground(Color.CYAN); this.add(availability, BorderLayout.CENTER); textLabel = new JLabel("Select a room:"); availability.setBorder(availabilityBorder); availability.add(textLabel); //Room button row JPanel buttonGroup = new JPanel(new FlowLayout(1)); buttonGroup.setBackground(Color.CYAN); ButtonGroup roomSize = new ButtonGroup(); JRadioButton singleRoom = new JRadioButton("Single"); singleRoom.setBackground(Color.CYAN); roomSize.add(singleRoom); JRadioButton doubleRoom = new JRadioButton("Double"); doubleRoom.setBackground(Color.CYAN); roomSize.add(doubleRoom); JRadioButton kingRoom = new JRadioButton("King"); kingRoom.setBackground(Color.CYAN); roomSize.add(kingRoom); buttonGroup.add(singleRoom); buttonGroup.add(doubleRoom); buttonGroup.add(kingRoom); availability.add(buttonGroup); //End room button row //Smoking row JPanel smokingPanel = new JPanel(new FlowLayout(1)); smokingPanel.setBackground(Color.CYAN); ButtonGroup smokingGroup = new ButtonGroup(); JRadioButton smoking = new JRadioButton("Smoking"); smoking.setBackground(Color.CYAN); smokingGroup.add(smoking); JRadioButton nonsmoking = new JRadioButton("Non-smoking"); nonsmoking.setBackground(Color.CYAN); smokingGroup.add(nonsmoking); smokingPanel.add(smoking); smokingPanel.add(nonsmoking); availability.add(smokingPanel); //End Smoking row //Month Menu JPanel monthPanel = new JPanel(new FlowLayout(3)); monthPanel.setBackground(Color.CYAN); textLabel = new JLabel("Select Month:"); monthPanel.add(textLabel); String[] months = { "Months", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; JComboBox monthList = new JComboBox(months); monthList.setSelectedIndex(0); monthPanel.add(monthList); //monthList.addActionListener(this); availability.add(monthPanel); //End Month Panel JPanel choose = new JPanel(new FlowLayout(1)); choose.setBackground(Color.CYAN); JButton chooseDates = new JButton("Choose Dates"); choose.add(chooseDates); availability.add(choose); //End Center Panel //East Panel Void //South Panel JPanel southPanel = new JPanel(new FlowLayout(1)); southPanel.setBackground(Color.BLUE); JButton reserve = new JButton("Reserve Room"); southPanel.add(reserve); JButton reset = new JButton("Reset"); southPanel.add(reset); this.add(southPanel, BorderLayout.SOUTH); //Reserve Room Reset //End South Panel addComponents(); } public void addComponents(){ } public void windowOpened(WindowEvent e){} public void windowClosing(WindowEvent e){ frame.dispose(); } public void windowClosed(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowDeiconified(WindowEvent e){} public void windowActivated(WindowEvent e){} public void windowDeactivated(WindowEvent e){} public void actionPerformed(ActionEvent e){} public static void createAndShowGUI(){ //Create and set up the window. frame = new JFrame("Hotel"); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); //Create content pane JComponent newContentPane = new Hotel(); newContentPane.setOpaque(true); frame.setContentPane(newContentPane); //Display frame.pack(); frame.setVisible(true); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub javax.swing.SwingUtilities.invokeLater(new Runnable(){ public void run(){ createAndShowGUI(); } }); } } [/HTML] I didn't add any actions to the buttons yet, but this is the basic build. I think I came pretty close to the example's design. |
|
|
|
|
|
#6 |
|
Sexy Programmer
|
you could save a lot of lines by using
[PHP] import javax.swing.*; import java.awt.*; import java.awt.event.*; [/PHP] thats only 3 lines vs your 18!
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Feb 2006
Location: Rochester, NY
Posts: 18
Rep Power: 0
![]() |
I use eclipse, so ctr shift o is easy
|
|
|
|
|
|
#8 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
|
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Feb 2006
Location: Rochester, NY
Posts: 18
Rep Power: 0
![]() |
I finished it, I don't like it. I rushed through it to meet the deadline and I don't think its worth posting. Sorry.
|
|
|
|
|
|
#10 | |
|
Programmer
Join Date: Feb 2006
Location: UK
Posts: 36
Rep Power: 0
![]() |
umm one thing...
Quote:
...Just a thought. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|