Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: hi, guys help me to write code in applets for below questions

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hi, guys help me to write code in applets for below questions

    Write a Java program that performs the task of a simple calculator.
    3 textboxes (2 input, 1 output)
    5 buttons (5 operators)
    2 labels (1 your name, 1 to display your index number in different colour and different font)
    Program name should display in the Title Bar


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    584
    My Mood
    Sleepy
    Thanks
    10
    Thanked 87 Times in 80 Posts

    Default Re: hi, guys help me to write code in applets for below questions

    Post your code and ask specific questions. Nobody will do it for you.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: hi, guys help me to write code in applets for below questions

    urgently need codes in java for airline reservation system;

    --- Update ---

    beginner and this is first project

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,143
    Thanks
    48
    Thanked 2,157 Times in 2,130 Posts

    Default Re: hi, guys help me to write code in applets for below questions

    We'll help you get your code to work. Post your code and your questions.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: hi, guys help me to write code in applets for below questions

    package airlinereservationsystem;

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;


    public class ReservationSystem extends JFrame implements ActionListener
    {
    private int seatCounter = 0;
    private JLabel userInstructions = new JLabel("Click the button" +
    " representing the seat you want " +
    "to reserve the seat");
    private JButton[] buttonArray = new JButton[12];
    private JButton exitButton = new JButton("Click to Exit");
    private boolean isReserved = true;

    public ReservationSystem()
    {
    super("SchexAirlines Reservation System");
    addWindowListener(new WindowDestroyer( ));
    Container contentPane = getContentPane( );
    contentPane.setLayout(new BorderLayout( ));
    JPanel InstructionsPanel = new JPanel( );
    JPanel buttonPanel = new JPanel( );
    JPanel exitPanel = new JPanel( );

    //add listener to the exit button
    exitButton.addActionListener(this);
    exitButton.setToolTipText("Click here when finished");

    InstructionsPanel.add(userInstructions);
    contentPane.add(InstructionsPanel, BorderLayout.NORTH);

    buttonPanel.setLayout(new GridLayout(5,3));

    for (int i=0;i<12;i++)
    {
    buttonArray[i] = new JButton("Seat " + (i+1));
    buttonArray[i].addActionListener(this);
    buttonArray[i].setToolTipText("Click to book seat");
    buttonPanel.add(buttonArray[i]);
    }
    contentPane.add(buttonPanel,BorderLayout.CENTER);
    exitPanel.add(exitButton);
    contentPane.add(exitPanel,BorderLayout.SOUTH);
    pack();
    }

    public void actionPerformed(ActionEvent e)
    {
    String confirmSeat = "Are you sure you want to book this seat?";
    String confirmQuit = "Are you sure you would like to quit?";
    String seatBooked = "Unbook seat? Click YES to unbook, or NO to " +
    "choose another seat.";
    for (int i = 0; i < 12; i++)
    {
    if (e.getActionCommand( ).equals("Seat " +(i + 1)))
    {
    int choice = JOptionPane.showConfirmDialog(null, confirmSeat,
    "Confirm Seat Selection",
    JOptionPane.YES_NO_OPTION);
    if(choice == JOptionPane.YES_OPTION)
    {
    buttonArray[i].setText("RESERVED");
    buttonArray[i].setToolTipText("Seat Taken");
    buttonArray[i].setForeground(Color.red);
    buttonArray[i].setActionCommand("booked");
    }
    }
    }

    if (e.getActionCommand( ).equals("Click to Exit"))
    {
    int choice = JOptionPane.showConfirmDialog(null, confirmQuit, "Confirm Quit",
    JOptionPane.YES_NO_OPTION);
    if(choice == JOptionPane.NO_OPTION)
    e.getActionCommand();
    else
    System.exit(0);
    }

    for(int i = 0; i < 12; i++)
    {
    if(e.getActionCommand().equals("booked"))
    {
    int choice = JOptionPane.showConfirmDialog(null, seatBooked, "Seat " +
    "Already Booked", JOptionPane.YES_NO_OPTION);
    if(choice == JOptionPane.YES_OPTION)
    {
    buttonArray[i].setText("Seat " + (i+1));
    buttonArray[i].setActionCommand("unbooked");
    e.getActionCommand();
    }
    else
    {
    buttonArray[i].setActionCommand("booked");
    e.getActionCommand();
    }
    }
    else
    e.getSource();
    }
    }
    @Override
    protected void processWindowEvent(WindowEvent e) {

    if (e.getID() == WindowEvent.WINDOW_CLOSING)
    {
    int exit = JOptionPane.showConfirmDialog(this, "Are you sure?");
    if (exit == JOptionPane.YES_OPTION)
    {
    System.exit(0);
    }
    }
    else
    {
    super.processWindowEvent(e);
    }
    }
    }

    --- Update ---

    package airlinereservationsystem;

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;


    public class ReservationSystem extends JFrame implements ActionListener
    {
    private int seatCounter = 0;
    private JLabel userInstructions = new JLabel("Click the button" +
    " representing the seat you want " +
    "to reserve the seat");
    private JButton[] buttonArray = new JButton[12];
    private JButton exitButton = new JButton("Click to Exit");
    private boolean isReserved = true;

    public ReservationSystem()
    {
    super("SchexAirlines Reservation System");
    addWindowListener(new WindowDestroyer( ));
    Container contentPane = getContentPane( );
    contentPane.setLayout(new BorderLayout( ));
    JPanel InstructionsPanel = new JPanel( );
    JPanel buttonPanel = new JPanel( );
    JPanel exitPanel = new JPanel( );

    //add listener to the exit button
    exitButton.addActionListener(this);
    exitButton.setToolTipText("Click here when finished");

    InstructionsPanel.add(userInstructions);
    contentPane.add(InstructionsPanel, BorderLayout.NORTH);

    buttonPanel.setLayout(new GridLayout(5,3));

    for (int i=0;i<12;i++)
    {
    buttonArray[i] = new JButton("Seat " + (i+1));
    buttonArray[i].addActionListener(this);
    buttonArray[i].setToolTipText("Click to book seat");
    buttonPanel.add(buttonArray[i]);
    }
    contentPane.add(buttonPanel,BorderLayout.CENTER);
    exitPanel.add(exitButton);
    contentPane.add(exitPanel,BorderLayout.SOUTH);
    pack();
    }

    public void actionPerformed(ActionEvent e)
    {
    String confirmSeat = "Are you sure you want to book this seat?";
    String confirmQuit = "Are you sure you would like to quit?";
    String seatBooked = "Unbook seat? Click YES to unbook, or NO to " +
    "choose another seat.";
    for (int i = 0; i < 12; i++)
    {
    if (e.getActionCommand( ).equals("Seat " +(i + 1)))
    {
    int choice = JOptionPane.showConfirmDialog(null, confirmSeat,
    "Confirm Seat Selection",
    JOptionPane.YES_NO_OPTION);
    if(choice == JOptionPane.YES_OPTION)
    {
    buttonArray[i].setText("RESERVED");
    buttonArray[i].setToolTipText("Seat Taken");
    buttonArray[i].setForeground(Color.red);
    buttonArray[i].setActionCommand("booked");
    }
    }
    }

    if (e.getActionCommand( ).equals("Click to Exit"))
    {
    int choice = JOptionPane.showConfirmDialog(null, confirmQuit, "Confirm Quit",
    JOptionPane.YES_NO_OPTION);
    if(choice == JOptionPane.NO_OPTION)
    e.getActionCommand();
    else
    System.exit(0);
    }

    for(int i = 0; i < 12; i++)
    {
    if(e.getActionCommand().equals("booked"))
    {
    int choice = JOptionPane.showConfirmDialog(null, seatBooked, "Seat " +
    "Already Booked", JOptionPane.YES_NO_OPTION);
    if(choice == JOptionPane.YES_OPTION)
    {
    buttonArray[i].setText("Seat " + (i+1));
    buttonArray[i].setActionCommand("unbooked");
    e.getActionCommand();
    }
    else
    {
    buttonArray[i].setActionCommand("booked");
    e.getActionCommand();
    }
    }
    else
    e.getSource();
    }
    }
    @Override
    protected void processWindowEvent(WindowEvent e) {

    if (e.getID() == WindowEvent.WINDOW_CLOSING)
    {
    int exit = JOptionPane.showConfirmDialog(this, "Are you sure?");
    if (exit == JOptionPane.YES_OPTION)
    {
    System.exit(0);
    }
    }
    else
    {
    super.processWindowEvent(e);
    }
    }
    }

  6. #6
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    584
    My Mood
    Sleepy
    Thanks
    10
    Thanked 87 Times in 80 Posts

    Default Re: hi, guys help me to write code in applets for below questions

    That's a start. Now wrap your code in code tags as described in the announcements and don't forget to ask a question.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,143
    Thanks
    48
    Thanked 2,157 Times in 2,130 Posts

    Default Re: hi, guys help me to write code in applets for below questions

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Also you forgot to post your questions.

    Also posted at: http://www.java-forums.org/java-appl...a-applets.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Several questions about my code
    By ProgrammerNoobE in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 23rd, 2013, 03:57 PM
  2. Replies: 7
    Last Post: May 8th, 2013, 02:33 PM
  3. Replies: 2
    Last Post: November 19th, 2012, 01:11 PM
  4. how to write answerable questions into java??
    By jingham in forum Java Theory & Questions
    Replies: 2
    Last Post: July 4th, 2012, 11:04 AM
  5. [SOLVED] Need Help ASAP with my code. should be an easy one for you guys!
    By GalBenH in forum What's Wrong With My Code?
    Replies: 13
    Last Post: December 5th, 2011, 07:27 PM