I am having major issues with layouts
This is my first post, so Hello! I should have started sooner in the semester. I am not asking for anyone to do my homework...I have the following code written but i cannot get my layout to look right.
the code is incomplete, because I havent done all my calculations and outputs, but I need my layout to work first. I KNOW I am using the wrong method, but I would love for someone to point me in the right direction...
Code Java:
/*
Chapter 6: Buy Movie Tickets
Programmer: Loyd Arthur
Date: 2/8/2012
Filename: Movies.java
Purpose: This program allows you to buy a number of tickets for a movie and specify
whether it is a matinee or not
*/
import java.awt.*;
import java.awt.event.*;
public class Movies extends Frame implements ActionListener, ItemListener
{
Panel layout;
Label titleLabel = new Label("Welcome to Celebration Movies");
Label answerLabel = new Label("");
Choice movieList = new Choice();
Choice numberOfTickets = new Choice();
Button calculateButton = new Button("Calculate");
String movieTitle;
int tickets;
double ticketPrice, totalPrice;
public Movies()
{
//set the layout
setLayout(new BorderLayout());
add(titleLabel, BorderLayout.NORTH);
add(movieList, BorderLayout.NORTH);
add(numberOfTickets, BorderLayout.CENTER);
add(calculateButton, BorderLayout.SOUTH);
add(answerLabel, BorderLayout.SOUTH);
movieList.addItemListener(this);
numberOfTickets.addItemListener(this);
calculateButton.addActionListener(this);
movieList.add("Fight Club");
movieList.add("Limitless");
movieList.add("Hackers");
movieList.add("Blade Runner");
movieList.add("300");
movieList.add("The Lord of the Ring: The Two Towers");
for(int i = 1; i<=8; i++)
numberOfTickets.add(String.valueOf(i));
//override the windowClosing event
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public void itemStateChanged(ItemEvent e)
{
{
String arg = movieList.getSelectedItem();
if (arg == "Fight Club")
movieTitle = ("Fight Club");
if (arg == "Limitless")
movieTitle = ("Limitless");
if (arg == "Hackers")
movieTitle = ("Hackers");
if (arg == "Blade Runner")
movieTitle = ("Blade Runner");
if (arg == "300")
movieTitle = ("300");
if (arg == "The Lord of the Ring: The Two Towers")
movieTitle = ("The Lord of the Ring: The Two Towers");
}
{
String arg = numberOfTickets.getSelectedItem();
if (arg == "1")
tickets =1;
if (arg == "2")
tickets =2;
if (arg == "3")
tickets =3;
if (arg == "4")
tickets =4;
if (arg == "5")
tickets =5;
if (arg == "6")
tickets =6;
if (arg == "7")
tickets =7;
if (arg == "8")
tickets =8;
}
}
public void actionPerformed(ActionEvent e)
{
String clicked = e.getActionCommand();
if(clicked == "Calculate")
{
totalPrice = (tickets * ticketPrice);
}
}
public static void main(String[] args)
{
// set frame properties
Movies f = new Movies();
f.setTitle("Celebration Movies");
f.setBounds(500,500,600,600);
f.setVisible(true);
}
}
Thanks in advance and sorry to be begging so drastically on my first post
Re: I am having major issues with layouts
I went with a GridLayout(6,0) because I have six items for the program...
it looks like crap, but im under the gun, so function over form today...
I still wouldn't mind a way to make the program look better for future reference.