How do I make JPanel focusable in applet?

Consider the following Applet: /*  <applet code="MyTest8" width="500" height="300"></applet>  */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyTest8 extends JApplet
     public void init()
          Container contentPane = getContentPane();
          contentPane.add(new MyTest8Panel());
class MyTest8Panel extends JPanel implements KeyListener
     String s;
     public MyTest8Panel()
          s="-";
          addKeyListener(this);
     public void paintComponent(Graphics g)
          super.paintComponent(g);
          g.drawString(s, 100, 100);
     public boolean isFocusable() { return true; }
     public void keyTyped(KeyEvent e) { s = s+"-"; repaint(); }
     public void keyPressed(KeyEvent e) { }
     public void keyReleased(KeyEvent e) { }
} It should add a dash to the screen everytime I hit a key. It doesn't work. It appears the panel never gets focus. What am I doing wrong?

Works fine using appletviewer on OS X panther

Similar Messages

  • How do I make firefox focus on the left tab by default after closing a tab?

    In all Firefox versions before 3, when closing a tab, focus automatically goes to the tab to the left of the viewed tab. This was consistent with the way Firefox opened tabs, which was to the right.
    For example: I have 3 tabs, ABC.
    I'm currently viewing tab B, and open a new tab using a link.
    Now I have tabs ABDC, with focus on D. Once I'm finished looking at D, I close tab D and should be viewing B again. Current settings eject me to tab C, which is unrelated.
    Is there a way to revert this behavior?

    Try Tabberwocky: https://addons.mozilla.org/firefox/addon/14439

  • How do I make an Applet read a file on my web host?

    How do I make an Applet read a file on my web host?
    I am wanting to put a file on my web host that has usernames and user details and other stuff on it...
    I was wondering whether anyone knows how to make the Applet open a file on my webserver, check if the username exists, if not add to the file the username and details?
    thanks

    URL myURL = new URL(getDocumentBase(), filename);
    InputStream myInputStream = myURL.openStream();
    DataInputStream dis = new DataInputStream(myInputStream);
    String oneLine = dis.readLine();
    Use output stream for writing..
    hope this works !!!

  • How do I make a button NOT take focus when it is clicked?

    I am trying to create a virtual keypad and the problem is that when I have a Robot make a KeyEvent for a certain number when a certain button is pressed, the TextField loses focus and the focus is placed on the button that was pressed, so nothing appears in the TextField.
    How can I make a button NOT take the focus when it is pressed?
    Edited by: tox0tes on Nov 28, 2008 8:06 PM

    great. another way is to have a call to myTextField.requestfocus() in the button's actionlistener actionPerformed method, but that leads to tight coupling.

  • After clicking on an open tab, how to make the focus automatically go to the body of page?

    After clicking on an open tab, how to make the focus automatically go to the body of page?
    Right now, clicking in an open tab and using arrow keys now moves through the open tabs. I liked the old versions where right after clicking in a tab you could directly go to navigate the page with the arrow keys.
    Is there a something I can change in about:config to change this behavior?
    Thanks in advanced.

    Firefox should still set the focus the the browser area if you click a tab.<br />
    Only with very old browser versions you could set the focus to a tab by clicking a tab.
    This behavior is likely caused by an extension.
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • In Flex,how to make lost focus of textinput on enter click?

    Hi
    In Flex,how to make lost focus of textinput on enter click of keyboard ?
    Thanks,
    Sunil

    Hi vibhuti,
         I  got your point but it will not helpful to me.
        But I found solution ,When user clicks enter key make stage.focus = null  so it will lost focus on text input and make focus in my current Alert Box.
    Thanks,
    Sunil

  • How to set FOCUS on applet (java-plugin)

    I wrote applet using Java 1.3.1, using swing clasess.
    I use java-plugin, defined in <object ..> and <embed ..> tags as described in documentation,
    with MAYSCRIPT parameter and ID and NAME parameters defined.
    How to set up focus on this applet through JavaScript?
    I have tried:
    document.embeds[0].focus()
    document.applets.MyApplet.focus()
    document.objects.MyApplet.focus()
    document.objects[0].focus()
    document.MyApplet.focus()
    But nothing works in my IE5.x or NC4.7. Applet itself works fine.
    Is some special methods need to be defined in JApplet to catch the focus?
    Thanks for any advice.

    I wrote applet using Java 1.3.1, using swing clasess.
    I use java-plugin, defined in <object ..> and <embed
    ..> tags as described in documentation,
    with MAYSCRIPT parameter and ID and NAME parameters
    defined.
    How to set up focus on this applet through
    JavaScript?
    I have tried:
    document.embeds[0].focus()
    document.applets.MyApplet.focus()
    document.objects.MyApplet.focus()
    document.objects[0].focus()
    document.MyApplet.focus()
    But nothing works in my IE5.x or NC4.7. Applet itself
    works fine.
    Is some special methods need to be defined in JApplet
    to catch the focus?
    Thanks for any advice.With IE you should try the following:
    <OBJECT id='MyApplet' ...
    document.MyApplet.requestFocus();
    This worked fine for me, even without specifying additional "MAYSCRIPT" or "scriptable=true" tags. Obviously this construct managed to call the public Java method "requestFocus()" from JavaScript.
    Maybe something similar would also work for Netscape. I felt no need to do this when running in Netscape, because the Netscape browser handled focus management without problems.
    For IE I tried to workaround a problem mentioned by several people in this forum: The focus will not be regained by an applet when the user switched form IE to another application and then returns back to the browser window which contains the applet.
    Unfortunally the following code fragment worked only partially well:
    function activated()
    if (isIE)
    document.MyApplet.requestFocus();
    return true;
    window.onfocus = activated();
    OnFocus is invoked only each second time when the browser window gains back focus.
    I'm still looking for a real solution, so I'd appreciate if anybody could come up with one.
    Hope this helps a bit
    Bernd

  • How to make JPanel as JTable Cell Editor (Urgent help needed)

    Hi!
    I want to make JPanel (with a JTextField, 3 JLabels and 1 JTextArea) as cell editor for one column. Can somebody help me on this?
    Does anybody have any sample code? I will greatly appreciate ur help.
    Thanks,
    Snehal

    Okie. In "How to use JTables" page found in the JAVA website (there is a link from the JTable section of the JAVA API documentation), there is a sample code for a sample color chooser. What this does is, adds a button with its action listener set to pop up a color chooser window. In this, rendering is still through a JLabel.
    This example would be of good help to you. Plus, this example gives me a feeling that what u ask is possible.

  • How can make Jpanel response click event?(help!)

    in a program i want to make jpanel response mouseclicked event, but jpanel class does not provide addActionListener(). through which way? i am able to arrive at the purpose! (create a new class extends jpanel, how to do?)
    thank a lot!!!

    Hello,
    have a look:import java.awt.Color;
    import java.awt.event.*;
    import javax.swing.*;
    public class ClickPanel extends JPanel implements MouseListener
         public static void main(String[]args)
              JFrame frame = new JFrame("Click-Panel");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.getContentPane().setLayout(null);
              frame.getContentPane().add(new ClickPanel());
              frame.setBounds(200,200,400,400);
              frame.setVisible(true);
         public ClickPanel()
              addMouseListener(this);
              setBounds(200,200,100,100);
              setBackground(Color.CYAN);
         public void mouseClicked(MouseEvent e)
              System.out.println("clicked");
         public void mouseEntered(MouseEvent e)
              System.out.println("entered");
              setBackground(Color.ORANGE);
         public void mouseExited(MouseEvent e)
              System.out.println("exited");
              setBackground(Color.CYAN);
         public void mousePressed(MouseEvent e)
              System.out.println("pressed");
         public void mouseReleased(MouseEvent e)
              System.out.println("released");
    }regards,
    Tim

  • How to make the focus to the TextInput field

    Hi,
            How to make the focus to the TextInput field. I tried with userIDTxtIt.setFocus();  The focus is available to the text input. but when i enter the value as 'Thiru' to the TextInput field, the keyboard is not available there. so i tried with userIDTxtIt.dispatchEvent(new MouseEvent(MouseEvent.DOUBLE_CLICK));
    still key board focus is not availble to the text input.
    Regards,
    Thiru

    Thanks for your reply.
       I got the more info by reading the comments inthe following link.
    http://blog.flexexamples.com/2008/09/23/setting-focus-in-flex-using-the-focus-manager/
    regards,
    Thiru

  • How to create a frame in a applet?

    Dear All,
    How to create a frame in a applet?
    Thanks in advance
    Kityy

    You can't add a Frame/JFrame to an Applet/JApplet.
    An Applet/JApplet has its origins in the class Panel/JPanel.
    So, if you make your Applet to an application you
    can easily do that by putting your Applet "above" a Frame.
    Maybe you can archieve your goals with some Panels?!

  • How can I make the combo box turn to the value of black.

    When the show button is pressed (and not before), a filled black square should be
    displayed in the display area. The combo box (or drop down list) that enables the user to choose the colour of
    the displayed shape and the altering should take effect immediately.When the show button is pressed,
    the image should immediately revert to the black square, the combo box should show the value that
    correspond to the black.
    Now ,the problem is: after I pressed show button, the image is reverted to the black square,but I don't know
    how can I make the combo box turn to the value of black.
    Any help or hint?Thanks a lot!
    coding 1.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class test extends JFrame {
         private JPanel buttonPanel;
         private DrawPanel myPanel;
         private JButton showButton;
         private JComboBox colorComboBox;
    private boolean isShow;
         private int shape;
         private boolean isFill=true;
    private String colorNames[] = {"black", "blue", "cyan", "darkGray", "gray",
    "green", "lightgray", "magenta", "orange",
    "pink", "red", "white", "yellow"}; // color names list in ComboBox
    private Color colors[] = {Color.black, Color.blue, Color.cyan, Color.darkGray,
                              Color.gray, Color.green, Color.lightGray, Color.magenta,
                              Color.orange, Color.pink, Color.red, Color.white, Color.yellow};
         public test() {
         super("Draw Shapes");
         // creat custom drawing panel
    myPanel = new DrawPanel(); // instantiate a DrawPanel object
    myPanel.setBackground(Color.white);
         // set up showButton
    // register an event handler for showButton's ActionEvent
    showButton = new JButton ("show");
         showButton.addActionListener(
              // anonymous inner class to handle showButton events
         new ActionListener() {
                   // draw a black filled square shape after clicking showButton
         public void actionPerformed (ActionEvent event) {
                             // call DrawPanel method setShowStatus and pass an parameter
              // to decide if show the shape
         myPanel.setShowStatus(true);
                   isShow = myPanel.getShowStatus();
                                            shape = DrawPanel.SQUARE;
                        // call DrawPanel method setShape to indicate shape to draw
                                            myPanel.setShape(shape);
                        // call DrawPanel method setFill to indicate to draw a filled shape
                                            myPanel.setFill(true);
                        // call DrawPanel method draw
                                            myPanel.draw();
                             myPanel.setFill(true);
                             myPanel.setForeground(Color.black);
                   }// end anonymous inner class
         );// end call to addActionListener
    // set up colorComboBox
    // register event handlers for colorComboBox's ItemEvent
    colorComboBox = new JComboBox(colorNames);
    colorComboBox.setMaximumRowCount(5);
    colorComboBox.addItemListener(
         // anonymous inner class to handle colorComboBox events
         new ItemListener() {
         // select shape's color
         public void itemStateChanged(ItemEvent event) {
         if(event.getStateChange() == ItemEvent.SELECTED)
         // call DrawPanel method setForeground
         // and pass an element value of colors array
         myPanel.setForeground(colors[colorComboBox.getSelectedIndex()]);
    myPanel.draw();
    }// end anonymous inner class
    ); // end call to addItemListener
    // set up panel containing buttons
         buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(4, 1, 0, 50));
         buttonPanel.add(showButton);
    buttonPanel.add(colorComboBox);
    JPanel radioButtonPanel = new JPanel();
    radioButtonPanel.setLayout(new GridLayout(2, 1, 0, 20));
    Container container = getContentPane();
    container.setLayout(new BorderLayout(10,10));
    container.add(myPanel, BorderLayout.CENTER);
         container.add(buttonPanel, BorderLayout.EAST);
    setSize(500, 400);
         setVisible(true);
         public static void main(String args[]) {
         test application = new test();
         application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    coding 2
    import java.awt.*;
    import javax.swing.*;
    public class DrawPanel extends JPanel {
         public final static int CIRCLE = 1, SQUARE = 2;
         private int shape;
         private boolean fill;
         private boolean showStatus;
    private int shapeSize = 100;
    private Color foreground;
         // draw a specified shape
    public void paintComponent (Graphics g){
              super.paintComponent(g);
              // find center
    int x=(getSize().width-shapeSize)/2;
              int y=(getSize().height-shapeSize)/2;
              if (shape == CIRCLE) {
         if (fill == true){
         g.setColor(foreground);
              g.fillOval(x, y, shapeSize, shapeSize);
    else{
                   g.setColor(foreground);
    g.drawOval(x, y, shapeSize, shapeSize);
              else if (shape == SQUARE){
         if (fill == true){
         g.setColor(foreground);
                        g.fillRect(x, y, shapeSize, shapeSize);
    else{
                        g.setColor(foreground);
    g.drawRect(x, y, shapeSize, shapeSize);
    // set showStatus value
    public void setShowStatus (boolean s) {
              showStatus = s;
         // return showstatus value
    public boolean getShowStatus () {
              return showStatus;
         // set fill value
    public void setFill(boolean isFill) {
              fill = isFill;
         // set shape value
    public void setShape(int shapeToDraw) {
              shape = shapeToDraw;
    // set shapeSize value
    public void setShapeSize(int newShapeSize) {
              shapeSize = newShapeSize;
    // set foreground value
    public void setForeground(Color newColor) {
              foreground = newColor;
         // repaint DrawPanel
    public void draw (){
              if(showStatus == true)
              repaint();

    Hello,
    does setSelectedIndex(int anIndex)
    do what you need?
    See Java Doc for JComboBox.

  • How can i make my scrollpane in a way that at the opening of a frame it doe

    How can i make my scrollpane in a way that at the opening of a frame it does not scroll down automatically?
    code is below
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.net.*;
    import javax.swing.JOptionPane.*;
    import java.io.*;
    import javax.swing.colorchooser.*;
    import javax.swing.filechooser.*;
    import javax.accessibility.*;
    import javax.swing.border.*;
    import java.sql.*;
    public class Signup extends JFrame
         JLabel p1,p2,p3,p4,p5,p6,uid,upass,cpass,fname,sname,hint,sl,ed,age,adr,cit,zip;
         JTextField uname,fnamet,snamet,hintt,adrt,adrt1,city,zipcode;
         JPasswordField upassw,cpassw;     
         JComboBox sex,education,agegr;
         Signup()
         Container c=getContentPane();
         c.setLayout(null);
         c.setBackground(Color.white);
         /** JPanel c = new JPanel();
         c.setBackground(Color.white);
         int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
         int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
         JScrollPane jsp = new JScrollPane(c, v, h); ***/
    p1=new JLabel("Create Your Icafe!ID",10);
         p2=new JLabel("Personal Information");
         p3=new JLabel("User Address");
         p4=new JLabel("Tell Us About Your Hobbiess (Optional) ");
         p5=new JLabel("Tell us something about what you like. This will help us choose the kind of content to display on           your pages.");
         p6=new JLabel("--------------------------------------------------------------------------------");
    uid=new JLabel("User Id");
         upass=new JLabel("Password");
         cpass=new JLabel("Confirmation Password");
         fname=new JLabel("UserName");
         sname=new JLabel("SurName");
         hint=new JLabel("Hint Question");
    sl=new JLabel("Sex");
         ed=new JLabel("Education");     
         age=new JLabel("Age Group");     
         adr=new JLabel("Address");
    cit=new JLabel("City");
    zip=new JLabel("ZipCode");
         uname=new JTextField(10);
         uname.requestFocus();     
         uname.setToolTipText("UserName");
    upassw=new JPasswordField(10);
         upassw.setToolTipText("Password");
         upassw.setEchoChar('*');
         cpassw=new JPasswordField(10);
         cpassw.setToolTipText("Confirmation Password");
         cpassw.setEchoChar('*');
         fnamet=new JTextField(10);
         fnamet.setToolTipText("FullName");
         snamet=new JTextField(10);
         snamet.setToolTipText("SurName");
         hintt=new JTextField(10);
         hintt.setToolTipText("Hint Question");     
    String[] gender={"[Select one]","Male","Female"};
         sex = new JComboBox(gender);          
    String[] edu={"[Select one]","S.S.C","Inter","Graduate","Post Graduate"};
         education= new JComboBox(edu);     
    String[] ageg={"[Select one]","0 - 15","16 - 35","36 - 70","70 - 100"};
         agegr= new JComboBox(ageg);     
    adrt=new JTextField(15);
         adrt.setToolTipText("Address");
         adrt1=new JTextField(15);
         adrt1.setToolTipText("Address");
         city=new JTextField(15);
         city.setToolTipText("City");
    zipcode=new JTextField(15);
         zipcode.setToolTipText("ZipCode");
         p1.setBounds(200,70,160,30);
         uid.setBounds(350,100,160,30);
         uname.setBounds(400,100,160,30);
         upass.setBounds(335,140,160,30);
         upassw.setBounds(400,140,160,30);
         cpass.setBounds(260,180,160,30);
         cpassw.setBounds(400,180,160,30);
         p2.setBounds(200,220,160,30);
         fname.setBounds(330,260,160,30);
         fnamet.setBounds(400,260,160,30);
         sname.setBounds(335,300,160,30);
         snamet.setBounds(400,300,160,30);
    hint.setBounds(315,340,160,30);     
    hintt.setBounds(400,340,160,30);
         sl.setBounds(370,380,160,30);     
         sex.setBounds(400,380,160,30);
         ed.setBounds(335,420,160,30);     
         education.setBounds(400,420,160,30);
    age.setBounds(330,460,160,30);
    agegr.setBounds(400,460,160,30);
    p3.setBounds(200,500,160,30);
         adr.setBounds(340,540,160,30);
         adrt.setBounds(400,540,160,30);
         adrt1.setBounds(400,580,160,30);
         cit.setBounds(370,620,160,30);
         city.setBounds(400,620,160,30);
    zip.setBounds(590,620,160,30);
    zipcode.setBounds(640,620,160,30);
         Font font = new Font("SansSerif",Font.BOLD, 12);
         setFont(font);
         c.add(p1);
    c.add(uid);
         c.add(uname);     
         c.add(upass);
         c.add(upassw);
    c.add(cpass);
         c.add(cpassw);
    c.add(p2);
    c.add(fname);     
         c.add(fnamet);
    c.add(sname);
    c.add(snamet);
         c.add(hint);
    c.add(hintt);     
    c.add(sl);
    c.add(sex);
    c.add(ed);
         c.add(education);
    c.add(age);
         c.add(agegr);
    c.add(p3);
    c.add(adr);
         c.add(adrt);
         c.add(adrt1);
    c.add(cit);
    c.add(city);
    c.add(zip);
    c.add(zipcode);
         setResizable(false);
         //int a=DO_NOTHING_ON_CLOSE;
         //setDefaultCloseOperation(a);
         show();
         setSize(800,500);
    // Border raisedBorder = new BevelBorder(BevelBorder.RAISED);     
         setContentPane(c);     
    public static void main (String arg[])
         try{
         UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
         }catch(Exception s)
         Signup swu=new Signup();

    just try the following:
    jsp.getVerticalScrollbar().setValue(0);after inserting and adding all your components. this will set the vertical scrollbar up to the very first line.
    regards

  • How can I make a backup listing of all of my Firefox bookmarks, with complete URLs, so I can print it out from a word processing document?

    == Issue
    ==
    I have a problem with my bookmarks, cookies, history or settings
    == Description
    ==
    How can I make a backup listing of all of my Firefox bookmarks, with completely written out URLs, so I can print it out from a word processing document? Please email me the answer-
    [email protected]
    <blockquote>duplicate. Locked. Please continue [https://support.mozilla.com/en-US/forum/1/727213 here] -MJB</blockquote>
    == Firefox version
    ==
    2.0.0.4
    == Operating system
    ==
    PPC Mac OS X Mach-O
    == User Agent
    ==
    Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
    == Plugins installed
    ==
    *-Netscape Navigator Default Plug-in
    *Runs Java applets using the latest installed versions of Java. For more information: Java Embedding Plugin. Run version test: Test Your JVM.
    *Plugin that plays RealMedia content
    *The QuickTime Plugin allows you to view a wide variety of multimedia content in web pages. For more information, visit the QuickTime Web site.
    *Shockwave Flash 9.0 r260
    *Provides support for Digital Rights Management
    *Provides support for Windows Media.
    *Java 1.3.1 Plug-in (CFM)
    *Macromedia Shockwave for Director Netscape plug-in, version 8.5.1
    *Java 1.3.1 Plug-in

    Hello.
    Although possibly not related to your problem, I have to remind you that the version of Firefox you are using at the moment has been discontinued and is no longer supported. On top of this, it has known unpatched bugs and security problems. I urge you to update to the latest version of Firefox, for maximum security, stability, performance and usability. You can get it for free, as always, at [http://www.getfirefox.com getfirefox.com].

  • How do I make this code generate a new pro when the "NEXT" button is pushed

    How do I make this code generate a new set of problem when the "NEXT" Button is pushed
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    /* Figure out how to create a new set of problms
    * Type a list of specifications, include a list of test cases
    * DONE :]
    package javaapplication1;
    import java.awt.GridLayout;
    import java.awt.Window;
    import javax.swing.*;
    import java.awt.event.*;
    * @author Baba Akinlolu -
    class Grid extends JFrame{
        int done = 0;
        final int score = 0;
        final int total = 0;           
            //Create Panels
            JPanel p2 = new JPanel();
            JPanel p3 = new JPanel();
            final JPanel p1 = new JPanel();
            //Create Radio buttons & group them
            ButtonGroup group = new ButtonGroup();
            final JRadioButton ADD = new JRadioButton("Addition");
            final JRadioButton SUB = new JRadioButton("Subtraction");
            final JRadioButton MUL = new JRadioButton("Multiplication");
            final JRadioButton DIV = new JRadioButton("Division");
            //Create buttons
            JButton NEXT = new JButton("NEXT");
            JButton END = new JButton("End");
            //Create Labels
            JLabel l1 = new JLabel("First num");
            JLabel l2 = new JLabel("Second num");
            JLabel l3 = new JLabel("Answer:");
            JLabel l4 = new JLabel("Score:");
            final JLabel l5 = new JLabel("");
            JLabel l6 = new JLabel("/");
            final JLabel l7 = new JLabel("");
            //Create Textfields
            final JTextField number = new JTextField(Generator1());
            final JTextField number2 = new JTextField(Generator1());
            final JTextField answer = new JTextField(5);
        Grid(){
            setLayout(new GridLayout(4, 4, 2 , 2));
            p2.add(ADD);
            p2.add(SUB);
            group.add(ADD);
            group.add(SUB);
            group.add(MUL);
            group.add(DIV);
            p2.add(ADD);
            p2.add(SUB);
            p2.add(DIV);
            p2.add(MUL);
            //Add to panels
            p1.add(l1);
            p1.add(number);
            p1.add(l2);
            p1.add(number2);
            p1.add(l3);
            p1.add(answer);
            p1.add(l4);
            p1.add(l5);
            p1.add(l6);
            p1.add(l7);
            p3.add(NEXT);
            p3.add(END);
            //Add panels
            add(p2);
            add(p1);
            add(p3);
            //Create Listners
            Listeners();
    void Listeners(){
          NEXT.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
             int answer1 = 0;
             //Grab the numbers entered
             int numm1 = Integer.parseInt(number.getText());
             int numm2 = Integer.parseInt(number2.getText());
             int nummsanswer = Integer.parseInt(answer.getText());
             //Set the score and total into new variabls
             int nummscore = score;
             int nummtotal = total;
             //Check if the add radio button is selected if so add
             if (ADD.isSelected() == true){
                 answer1 = numm1 + numm2;
             //otherwise check if the subtract button is selected if so subtract
             else if (SUB.isSelected() == true){
                 answer1 = numm1 - numm2;
             //check if the multiplication button is selected if so multiply
             else if (MUL.isSelected() == true){
                 answer1 = numm1 * numm2;
             //check if the division button is selected if so divide
             else if (DIV.isSelected() == true){
                 answer1 = numm1 / numm2;
             //If the answer user entered is the same with th true answer
             if (nummsanswer == answer1){
                 //add to the total and score
                 nummtotal += 1;
                 nummscore += 1;
                 //Convert the input back to String
                 String newscore = String.valueOf(nummscore);
                 String newtotal = String.valueOf(nummtotal);
                 //Set the text
                 l5.setText(newscore);
                 l7.setText(newtotal);
             //Otherwise just increase the total counter
             else {
                 nummtotal += 1;
                 String newtotal = String.valueOf(nummtotal);
                 l7.setText(newtotal);
      //Create End listener
    END.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // get the root window and call dispose on it
            Window win = SwingUtilities.getWindowAncestor(p1);
            win.dispose();
    //new Grid();
    String Generator1(){
         int randomnum;
         randomnum = (1 + (int)(Math.random() * 100));
         String randomnumm = String.valueOf(randomnum);
         return randomnumm;
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            JFrame frame = new Grid();
            frame.setTitle("Flashcard Testing");
            frame.setSize(500, 200);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    }Edited by: SirSaula on Dec 7, 2009 10:17 AM

    Not only are you continuing to post in the wrong forum but now you are multiposting: [http://forums.sun.com/thread.jspa?threadID=5418935]
    If people haven't answered you other posting its probably because we don't understand the question. Quit cluttering the forum by asking the same question over and over and then next time you have a new question post it in the proper forum. Your first posting was moved becuase you didn't post it properly.

Maybe you are looking for