Google Answers Logo
View Question
 
Q: Java Program ( No Answer,   0 Comments )
Question  
Subject: Java Program
Category: Computers > Programming
Asked by: math01-ga
List Price: $2.50
Posted: 10 Feb 2003 09:49 PST
Expires: 11 Feb 2003 12:03 PST
Question ID: 159526
I am trying to run the gui program below but can not get it to run.

import java.awt.*;  
import javax.swing.*;  
  
public class NewGUI extends JApplet {  
       
    // set up row 1  
    JPanel row1 = new JPanel();  
    JLabel ptLabel = new JLabel("Choose: ");  
    JComboBox playType = new JComboBox();  
    // set up row 2  
    JPanel row2 = new JPanel();  
    JLabel numbersLabel = new JLabel("Your picks: ", JLabel.RIGHT);  
    JTextField[] numbers = new JTextField[6];  
    JLabel winnersLabel = new JLabel("Winners: ", JLabel.RIGHT);  
    JTextField[] winners = new JTextField[6];  
    // set up row 3  
    JPanel row3 = new JPanel();  
    ButtonGroup option = new ButtonGroup();  
    JCheckBox stop = new JCheckBox("Stop", true);  
    JCheckBox play = new JCheckBox("Play", false);  
    JCheckBox reset = new JCheckBox("Reset", false);  
    // set up row 4  
    JPanel row4 = new JPanel();  
    JLabel got3Label = new JLabel("3 of 6: ", JLabel.RIGHT);  
    JTextField got3 = new JTextField();  
    JLabel got4Label = new JLabel("4 of 6: ", JLabel.RIGHT);  
    JTextField got4 = new JTextField();  
    JLabel got5Label = new JLabel("5 of 6: ", JLabel.RIGHT);  
    JTextField got5 = new JTextField();  
    JLabel got6Label = new JLabel("6 of 6: ", JLabel.RIGHT);  
    JTextField got6 = new JTextField(10);  
    JLabel drawingsLabel = new JLabel("Drawings: ", JLabel.RIGHT);  
    JTextField drawings = new JTextField();  
    JLabel yearsLabel = new JLabel("Years: ", JLabel.RIGHT);  
    JTextField years = new JTextField();  
      
    public void init() {  
        GridLayout appletLayout = new GridLayout(5, 1, 10, 10);  
        Container pane = getContentPane();  
        pane.setLayout(appletLayout);  
  
        FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER,  
            10, 10);  
        row1.setLayout(layout1);  
        playType.addItem("Quick Pick");  
        playType.addItem("Personal");  
        row1.add(ptLabel);  
        row1.add(playType);  
        pane.add(row1);  
  
        GridLayout layout2 = new GridLayout(2, 7, 10, 10);  
        row2.setLayout(layout2);  
        row2.setLayout(layout2);  
        row2.add(numbersLabel);  
        for (int i = 0; i < 6; i++) {  
            numbers[i] = new JTextField();  
            row2.add(numbers[i]);  
        }  
        row2.add(winnersLabel);  
        for (int i = 0; i < 6; i++) {  
            winners[i] = new JTextField();  
            winners[i].setEditable(false);  
            row2.add(winners[i]);  
        }  
        pane.add(row2);  
  
        FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER,  
            10, 10);  
        option.add(stop);  
        option.add(play);  
        option.add(reset);  
        row3.setLayout(layout3);  
        row3.add(stop);  
        row3.add(play);  
        row3.add(reset);  
        pane.add(row3);  
  
        GridLayout layout4 = new GridLayout(2, 6, 20, 10);  
        row4.setLayout(layout4);  
        row4.add(got3Label);  
        got3.setEditable(false);  
        row4.add(got3);  
        row4.add(got4Label);  
        got4.setEditable(false);  
        row4.add(got4);  
        row4.add(got5Label);  
        got5.setEditable(false);  
        row4.add(got5);  
        row4.add(got6Label);  
        got6.setEditable(false);  
        row4.add(got6);  
        row4.add(drawingsLabel);  
        drawings.setEditable(false);  
        row4.add(drawings);  
        row4.add(yearsLabel);  
        years.setEditable(false);  
        row4.add(years);  
        pane.add(row4);  
        setContentPane(pane);  
    }  
    public static void main(String[] arguments) {  
       NewGUI ng = new NewGUI();  
    }    
}

Request for Question Clarification by secret901-ga on 10 Feb 2003 11:02 PST
Hi math01,
Is your class intended to be used as an applet or an application? 
With the inclusion of the main() method, it appears that you want to
make an application.
But the JApplet class is more suitable for applets embedded in web
pages.

Clarification of Question by math01-ga on 10 Feb 2003 13:18 PST
Hi secret901-ga,

My class is intended to be use as both.

Thanks

Request for Question Clarification by secret901-ga on 10 Feb 2003 15:57 PST
Hi math01,
Your program runs properly as an applet.  If you wish to make an
application out of it, consider converting it into a JFrame.

secret901-ga

Request for Question Clarification by studboy-ga on 10 Feb 2003 19:49 PST
Hi Math01,

The correct way to do this is the put add a JFrame class--
call your JApplet from within JFrame--
Then it becomes "both"...

Clarification of Question by math01-ga on 11 Feb 2003 00:43 PST
Can you please provide the code and procedure on how to have this
program run successfully?
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy