Results 1 to 3 of 3
  1. #1
    bdmchamp is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Post Applet Wont Show Supposed Output, Please Help

    Hi I've been trying to write an applet that suppose to show a price for a user input of guest at a event. It should have 2 int arrays( one for the prices and one for the users input of the guest). I having horrific trouble, I've been trying for 3 days now to complete this thing, but i cant! I'm not asking for the answer, but a step in the rite direction would be greatly, greatly appreciated. I'm sure its prolly an easier way to write this, but i'm new to java and i like it and everything but i'm getting really frustrated as i dont know how to produce my wanted results. Please Help
    here is the code that i have so far:




    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;


    public class JPartyPlanner extends JApplet implements ActionListener
    {



    JLabel greeting1 = new JLabel("Give A Hand");
    JLabel greeting2 = new JLabel("Event Planning");
    JLabel question = new JLabel("How many people will be attending?");
    JLabel output = new JLabel(" ");
    JTextField answer = new JTextField(6);
    JButton calperson = new JButton("Calculate per person");
    JButton calcost = new JButton("Calculate total cost");
    Container con = getContentPane();
    Font font1 = new Font("Times New Roman", Font.ITALIC, 60);
    Font font2 = new Font("Ariel", Font.BOLD, 30);
    Font font3 = new Font("Teen", Font.BOLD, 15);


    public void init()
    {


    question.setFont(font3);
    greeting1.setFont(font1);
    greeting2.setFont(font1);
    con.setLayout(new FlowLayout());
    con.setBackground(Color.GREEN);
    con.add(greeting1);
    con.add(greeting2);
    con.add(question);
    con.add(answer);
    con.add(calperson);
    con.add(calcost);
    calperson.addActionListener(this);
    calcost.addActionListener(this);


    }



    public void actionPerformed(ActionEvent e)
    {
    Object source = e.getSource();
    int x;
    int[] numberPeople = {24, 49, 99, 199, 499, 999, 1000};
    double[] costPerson = {27.00, 25.00, 22.00, 19.00, 17.00, 14.00, 11.00};
    String[] numberPeople1 = new String[7];
    final int ITEMS = 7;
    String costPerson1;






    if(source == calperson)

    {con.add(greeting1);
    con.add(greeting2);
    con.add(question);
    con.add(answer);
    con.add(calperson);
    con.add(calcost);
    con.add(output);
    con.setBackground(Color.RED);
    con.setLayout(new FlowLayout());
    greeting1.setFont(font1);
    greeting2.setFont(font1);
    output.setText(" ");
    output.setFont(font2);
    answer.setText(" ");

    for(x = 0; x<ITEMS; ++x)
    numberPeople1[x] = Integer.toString(numberPeople[x]);

    if( answer.getText() == numberPeople1[x])
    {costPerson1 = Double.toString(costPerson[x]);
    output.setText(costPerson1);}






    validate();}
    }

    public static void main(String[] args)
    {
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    Does the code you posted compile? If not, please post the full text of the error messages.
    Why is there a main() method at the end of your code? Applets don't use that method.

    Don't use == to compare two Strings. Use the equals() method.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

Similar Threads

  1. Applet Wont Show Supposed Output, Please Help!!!!
    By bdmchamp in forum New To Java
    Replies: 7
    Last Post: 06-26-2011, 11:43 PM
  2. Graphics wont show up(paintComponent)
    By TheBreadCat in forum New To Java
    Replies: 3
    Last Post: 02-13-2011, 06:00 PM
  3. wont show entire JLabel
    By Billaguana in forum AWT / Swing
    Replies: 6
    Last Post: 02-03-2011, 10:18 PM
  4. output to applet
    By shivi24 in forum New To Java
    Replies: 6
    Last Post: 06-11-2010, 08:23 PM
  5. Formatting this output to show "#.##"
    By twiggy62 in forum New To Java
    Replies: 9
    Last Post: 02-06-2010, 05:40 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
  •