Question on homework....

Discussion in 'Java' started by simple, Nov 18, 2012.

  1. simple

    simple Guest

    Working on this homework - need to have java when launched the program showthe main intro window (which it does show me) and then I need to show the welcome page but don't know how to make this appear right after. The last step is it has to show me the rules windows but not sure how I tell the system the user wants to see the rules.

    When I run the batch file the intro window appears for a few seconds but not the other window why is it not picking up???? I don't understand where it is getting the if type==1 ??? where is getting 1 from??? Do I need to create menu to ask for type 1 or 2??? Would really appreciate if someonecan clarify why it is not working.....

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


    public class window extends JWindow
    {

    ImageIcon imIntro = new ImageIcon("images\\Lintro.jpg");
    ImageIcon imWelcome = new ImageIcon("images\\Welcome.jpg");
    ImageIcon imRules = new ImageIcon("images\\Rules.jpg");
    static Thread t = new Thread();
    static int thread = 0;
    static JButton bouton;
    static int X;
    static int Y;

    /* Parametres du constructeur :
    type: 1-> Intro, 2->rules */

    public window( int X, int Y, int type ) {

    super();
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(X,Y);
    setLocation( (dim.width - X)/2 , (dim.height - Y)/2);
    setVisible(true);
    Container fen = getContentPane();

    if (type == 1 ) bouton = new JButton(imIntro);
    else bouton = new JButton(imRules);
    bouton.setPreferredSize(new Dimension(X, Y) );
    fen.add(bouton);
    bouton.setVisible(true);

    show();

    if( type == 1 ) { //this is the part I don't know where is it getting it
    try {
    t.sleep(2000);
    thread = 1;
    }
    catch( java.lang.InterruptedException ex ) {
    JOptionPane.showMessageDialog(null, "error");
    }
    dispose();

    }
    /* If it is the rules - close window when user cliques*/

    else {
    bouton.addActionListener( new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    dispose();
    }
    });
    }

    }
    }
     
    simple, Nov 18, 2012
    #1
    1. Advertising

  2. On 11/18/2012 3:45 PM, simple wrote:
    > Working on this homework - need to have java when launched the
    > program show the main intro window (which it does show me) and then I
    > need to show the welcome page but don't know how to make this appear
    > right after. The last step is it has to show me the rules windows
    > but not sure how I tell the system the user wants to see the rules.
    >
    > When I run the batch file the intro window appears for a few seconds
    > but not the other window why is it not picking up???? I don't
    > understand where it is getting the if type==1 ??? where is getting 1
    > from??? Do I need to create menu to ask for type 1 or 2??? Would
    > really appreciate if someone can clarify why it is not working.....
    >
    > import javax.swing.*; import java.awt.*; import java.awt.event.*;
    >
    >
    > public class window extends JWindow {
    >
    > ImageIcon imIntro = new ImageIcon("images\\Lintro.jpg"); ImageIcon
    > imWelcome = new ImageIcon("images\\Welcome.jpg"); ImageIcon imRules =
    > new ImageIcon("images\\Rules.jpg"); static Thread t = new Thread();
    > static int thread = 0; static JButton bouton; static int X; static
    > int Y;
    >
    > /* Parametres du constructeur : type: 1-> Intro, 2->rules */
    >
    > public window( int X, int Y, int type ) {
    >
    > super(); Dimension dim =
    > Toolkit.getDefaultToolkit().getScreenSize(); setSize(X,Y);
    > setLocation( (dim.width - X)/2 , (dim.height - Y)/2);
    > setVisible(true); Container fen = getContentPane();
    >
    > if (type == 1 ) bouton = new JButton(imIntro); else bouton
    > = new JButton(imRules); bouton.setPreferredSize(new Dimension(X, Y)
    > ); fen.add(bouton); bouton.setVisible(true);
    >
    > show();
    >
    > if( type == 1 ) { //this is the part I don't know where is it getting
    > it try { t.sleep(2000); thread = 1; } catch(
    > java.lang.InterruptedException ex ) {
    > JOptionPane.showMessageDialog(null, "error"); } dispose();
    >
    > } /* If it is the rules - close window when user cliques*/
    >
    > else { bouton.addActionListener( new ActionListener() { public void
    > actionPerformed(ActionEvent e) { dispose(); } }); }
    >
    > } }
    >


    You've got a lot of problems with this code. You can't sleep in the
    constructor. All GUI construction needs to be done on the Event
    Dispatch Thread. show() has been deprecated for setVisible(true). You
    don't have any main() method (or you haven't shown us all the code).

    So it sounds like you have three windows you want to display. You
    should create three classes with the code that each of these windows
    needs to function. If you want a window to disappear after a period of
    time, use a javax.swing.Timer, that you start when the window is opened,
    to close that window and open the next one. If you are using a JButton,
    in the button's ActionListener, close the one window and open the next.

    --

    Knute Johnson
     
    Knute Johnson, Nov 19, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    0
    Views:
    692
    Guest
    Feb 25, 2004
  2. Rhino

    need help with homework

    Rhino, Nov 16, 2003, in forum: Java
    Replies:
    1
    Views:
    309
    Roedy Green
    Nov 16, 2003
  3. Andrew Thompson
    Replies:
    33
    Views:
    912
    Alex Hunsley
    Oct 30, 2004
  4. xscarsofdesirex

    Homework Help! Urgent!

    xscarsofdesirex, Feb 27, 2005, in forum: Java
    Replies:
    5
    Views:
    546
    Alun Harford
    Feb 28, 2005
  5. Three Headed Monkey

    not a homework question

    Three Headed Monkey, Mar 12, 2008, in forum: C Programming
    Replies:
    35
    Views:
    882
    user923005
    Mar 17, 2008
Loading...

Share This Page