Results 1 to 3 of 3
  1. #1
    dekon is offline Member
    Join Date
    Aug 2011
    Posts
    8
    Rep Power
    0

    Default middle buttons and bottom text area boxes missing in GUI

    i'm having trouble with my text area boxes on the bottom of my GUI and also the middle buttons on my GUI could you help me solve this reason sa when i run the program they are not showing thanks
    the code is

    import static javax.swing.JOptionPane.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.*;
    import java.text.DecimalFormat;

    public class ticket extends JFrame implements ActionListener {

    static final double SINGLE = 1.40;
    static final double RETURN = 2.40;
    static final double ZONE_A = 3.80;
    static final double ZONE_A_B = 5.50;

    DecimalFormat pounds = new DecimalFormat("0.00");
    private String id;
    JTextField ticket = new JTextField(5);
    JTextField stp = new JTextField(5);
    int amount = 0; //pay in pence
    JTextField change = new JTextField(5);
    JTextField paid = new JTextField(5);
    JButton ten = new JButton("10p");
    JButton twenty = new JButton("20p");
    JButton fifty = new JButton("50p");
    JButton pound = new JButton("1");
    JButton two = new JButton("2");
    JButton five = new JButton("5");
    JButton tenp = new JButton("10");
    JButton twentyp = new JButton("20");
    JButton cancel = new JButton("Cancel");
    JRadioButton single = new JRadioButton("single (1.40)",false);
    JRadioButton Return = new JRadioButton("return (2.40)",false);
    JRadioButton zoneA = new JRadioButton("Zone A (3.80)",false);
    JRadioButton zoneAB = new JRadioButton("Zone A B (5.50)",false);
    ButtonGroup type =new ButtonGroup();
    // The spinner give double values in the range 1 to 10.
    // From the spinner, the user can only purchase 10 tickets at a time!
    private JSpinner numtick = new JSpinner(new SpinnerNumberModel(1, 0, 10, 1));
    private int stpno = 0;
    private int size = 0;
    // Set as private so that it can only be used in this class and no others. Set as public to be used in other classes.

    public static void main(String[] args)
    {
    new ticket();
    }
    public ticket()
    {
    setLayout(new BorderLayout());
    setSize(700, 150);
    setTitle("Redwich Trams - Ticket Machine");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel top = new JPanel();
    top.setLayout(new FlowLayout());
    top.add(new JLabel("Ticket Type: "));

    type.add(single);
    type.add(Return);
    type.add(zoneA);
    type.add(zoneAB);
    top.add(single);
    top.add(Return);
    top.add(zoneA);
    top.add(zoneAB);
    top.add(new JLabel(" Tickets"));
    top.add(numtick);
    single.addActionListener(this);
    Return.addActionListener(this);
    zoneA.addActionListener(this);
    zoneAB.addActionListener(this);

    add("North", top);
    setVisible(true);

    JPanel middle = new JPanel();
    middle.setLayout(new FlowLayout());
    middle.add(new JLabel("Ticket Type: "));
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOS E);
    middle.add(ten);
    middle.add(twenty);
    middle.add(fifty);
    middle.add(pound);
    middle.add(two);
    middle.add(five);
    middle.add(tenp);
    middle.add(twentyp);
    middle.add(cancel);
    ten.addActionListener(this);
    twenty.addActionListener(this);
    fifty.addActionListener(this);
    pound.addActionListener(this);
    two.addActionListener(this);
    five.addActionListener(this);
    tenp.addActionListener(this);
    twentyp.addActionListener(this);
    cancel.addActionListener(this);

    add("Center", middle);
    setVisible(true);

    JPanel bottom = new JPanel();
    bottom.setLayout(new FlowLayout());
    bottom.add(new JLabel(" Ticket Cost:"));
    bottom.add(ticket);
    bottom.add(new JLabel(" Amount Paid:"));
    bottom.add(paid);
    bottom.add(new JLabel(" Amount Still To Pay:"));
    bottom.add(stp);
    stp.setEditable(false);
    bottom.add(new JLabel(" Change:"));
    bottom.add(change);
    ticket.setEditable(false);
    paid.setEditable(false);

    change.setEditable(false);
    ticket.setText("0.00");
    stp.setText("0.00");
    change.setText("0.00");
    paid.setText("0.00");
    add("South", bottom);
    setVisible(true);
    }

    the GUI shows the top radio buttons when run but nothing else any help would be much appreciated thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default

    The code you posted does not compile without errors.

    Did you leave off some of the code???


    Please enclose the code in code tags. See: http://www.java-forums.org/misc.php?do=bbcode#code

  3. #3
    dekon is offline Member
    Join Date
    Aug 2011
    Posts
    8
    Rep Power
    0

    Default

    hi i've managed to solve it now i think there was some kind of bug with running the program thanks

Similar Threads

  1. Replies: 3
    Last Post: 07-04-2011, 01:50 PM
  2. Get text from multiple text boxes/tables
    By greenhorn in forum New To Java
    Replies: 0
    Last Post: 03-08-2011, 04:32 PM
  3. JFrame-buttons missing
    By Jodokus in forum AWT / Swing
    Replies: 5
    Last Post: 01-20-2011, 06:10 PM
  4. custom graphics, buttons & drop boxes
    By jaytee in forum New To Java
    Replies: 1
    Last Post: 03-14-2010, 01:27 AM
  5. Replies: 2
    Last Post: 01-23-2009, 05:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •