RequestFocus fail in JApplet

I wrote a JPanel under a JApplet, I want to focus on a particular JTextField, but failed to do so. Here is my code.
<pre>
this.setSize(new Dimension(324,250));
this.getContentPane().add(JPanel1,new XYConstraints(0,0,324,250));
JPanel1.setVisible(true);
JPanel1.jTextField.requestFocus();
</pre>
hope anyone can help me. Thank you
puikay

Does anyone know how to solve this problem? Urgent need. Thank you

Similar Messages

  • JApplet with JFrame fails to load in browser

    I have been making a Java program that runs a JApplet the program operates perfectly in NetBeans (the Java development kit), but when I run it in the browser, it fails to load.
    The code is...
    import java.awt.*;
    import javax.swing.*;
    public class CalculatorMain extends javax.swing.JApplet {
    private Difficulty difficulty = new Difficulty();
    private Troop[] troop = new Troop[7];
    private Army army = new Army(troop);
    private Calculator calculator = new Calculator(difficulty, army);
    private CalculatorListener listener;
    public void init(){
    JPanel supreme = new JPanel();
    supreme.setLayout(new BorderLayout());
    for (byte i = 0; i < 7; i++) {troop[i] = new Troop();}
    DifficultyPanel diffpanel = new DifficultyPanel(difficulty);
    ArmyPanel armypanel = new ArmyPanel(troop);
    JButton calbut = new JButton("Calculate Experience");
    JLabel xpDisplay = new JLabel(" ");
    CalculatorPanel calpanel = new CalculatorPanel(calculator, calbut, xpDisplay);
    JFrame frame = new JFrame();
    listener = new CalculatorListener(xpDisplay, calculator, diffpanel, armypanel, calpanel);
    calbut.addActionListener(listener);
    supreme.add(diffpanel, BorderLayout.WEST);
    supreme.add(armypanel, BorderLayout.CENTER);
    supreme.add(calpanel, BorderLayout.SOUTH);
    frame.add(supreme);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    As I said, it does not work in the web browser (which is Internet Explorer 6.0). In the information window I open, the message is...
    Java Plug-in 1.5.0_06
    Anv�nder JRE-version 1.5.0_06 Java HotSpot(TM) Client VM
    java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkExit(Unknown Source)
         at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source)
         at CalculatorMain.init(CalculatorMain.java:31)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Exception in thread "thread applet-CalculatorMain.class" java.lang.NullPointerException
         at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
         at sun.plugin.AppletViewer.showAppletException(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Any idea what might be wrong?

    If you look at your error message you'll see...
    java.security.AccessControlException: access deniedAh. Problem # 1 caused at
         at CalculatorMain.init(CalculatorMain.java:31)Problem #2
    java.lang.NullPointerExceptionat
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)So it says it can't display the init error message. That's ok this should go away when you fix bug #1

  • How can I change my JApplet into a JApplication?

    I am working with a JApplet and am finding that some of my code only works in applications.
    So being new to this, I am clueless as to how to change my Applet into an Application. I understand the difference in definition between the two, but when it comes to looking at Applet Code and Application Code, I am not able to see a difference. (Other than an Applet stating "Applet")
    So, that being said how can I change my code so that it runs as an application and not an applet? Here is my current layout code
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    // Creating the main class
    public class test extends JApplet implements ActionListener
         // Defining of format information
         JLabel heading = new JLabel("McBride Financial Services Mortgage Calculator");
         Font newFontOne = new Font("TimesRoman", Font.BOLD, 20);
         Font newFontTwo = new Font("TimesRoman", Font.ITALIC, 16);
         Font newFontThree = new Font("TimesRoman", Font.BOLD, 16);
         Font newFontFour = new Font("TimesRoman", Font.BOLD, 14);
         JButton calculate = new JButton("Calculate");
         JButton exitButton = new JButton("Quit");
         JButton clearButton = new JButton("Clear");
         JLabel instructions = new JLabel("Please Enter the Principal Amount Below");
         JLabel instructions2 = new JLabel("and Select a Loan Type from the Menu");
         // Declaration of variables
         private double principalAmount;
         private JLabel principalLabel = new JLabel("Principal Amount");
         private NumberFormat principalFormat;
         private JTextField enterPrincipal = new JTextField(10);
         private double finalPayment;
         private JLabel monthlyPaymentLabel = new JLabel("  Monthly Payment    \t         Interest Paid    \t \t            Loan Balance");
         private NumberFormat finalPaymentFormat;
         private JTextField displayMonthlyPayment = new JTextField(10);
         private JTextField displayInterestPaid = new JTextField(10);
         private JTextField displayBalance = new JTextField(10);
         // Creation of the String of arrays for the ComboBox
         String [] list = {"7 Years @ 5.35%", "15 Years @ 5.50%", "30 Years @ 5.75%"};
         JComboBox selections = new JComboBox(list);
         // Creation of the textArea that will display the output
         private TextArea txtArea = new TextArea(5, 10);
         StringBuffer buff = null;
         // Initializing the interface
         public void init()
              // Creation of the panel design and fonts
              JPanel upper = new JPanel(new BorderLayout());
              JPanel middle = new JPanel(new BorderLayout());
              JPanel lower = new JPanel(new BorderLayout());
              JPanel areaOne = new JPanel(new BorderLayout());
              JPanel areaTwo = new JPanel(new BorderLayout());
              JPanel areaThree = new JPanel(new BorderLayout());
              JPanel areaFour = new JPanel(new BorderLayout());
              JPanel areaFive = new JPanel(new BorderLayout());
              JPanel areaSix = new JPanel(new BorderLayout());
              Container con = getContentPane();
              getContentPane().add(upper, BorderLayout.NORTH);
              getContentPane().add(middle, BorderLayout.CENTER);
              getContentPane().add(lower, BorderLayout.SOUTH);
              upper.add(areaOne, BorderLayout.NORTH);
              middle.add(areaTwo, BorderLayout.NORTH);
              middle.add(areaThree, BorderLayout.CENTER);
              middle.add(areaFour, BorderLayout.SOUTH);
              lower.add(areaFive, BorderLayout.NORTH);
              lower.add(areaSix, BorderLayout.SOUTH);
              heading.setFont(newFontOne);
              instructions.setFont(newFontTwo);
              instructions2.setFont(newFontTwo);
              principalLabel.setFont(newFontThree);
              monthlyPaymentLabel.setFont(newFontFour);
              displayInterestPaid.setFont(newFontFour);
              displayBalance.setFont(newFontFour);
              areaOne.add(heading, BorderLayout.NORTH);
              areaOne.add(instructions, BorderLayout.CENTER);
              areaOne.add(instructions2, BorderLayout.SOUTH);
              areaTwo.add(principalLabel, BorderLayout.WEST);
              areaTwo.add(enterPrincipal, BorderLayout.EAST);
              areaThree.add(selections, BorderLayout.NORTH);
              areaFour.add(calculate, BorderLayout.CENTER);
              areaFour.add(exitButton, BorderLayout.EAST);
              areaFour.add(clearButton, BorderLayout.WEST);
              areaFive.add(monthlyPaymentLabel, BorderLayout.CENTER);
              areaSix.add(txtArea, BorderLayout.CENTER);
              // Using the ActionListener to determine when each button is clicked
              calculate.addActionListener(this);
              exitButton.addActionListener(this);
              clearButton.addActionListener(this);
              enterPrincipal.requestFocus();
              selections.addActionListener(this);
         }

    baftos wrote:
    Here is one of the sites that explains the procedure:
    [http://leepoint.net/notes-java/deployment/applications_and_applets/70applets.html].
    But maybe you should try to fix the code that does not work as applet?
    Which one is it?
    >Here is one of the sites that explains the procedure:
    [http://leepoint.net/notes-java/deployment/applications_and_applets/70applets.html].
    But maybe you should try to fix the code that does not work as applet?
    Which one is it?
    The code that doesn't work in my applet is the exit button code
    else if (source == exitButton)
                        System.exit(1);
                   }I also can't get my program to properly validate input. When invalid input is entered and the user presses calculate, an error window should pop up. Unfortunately it isn't. I compile and run my applications/applets through TextPad. So when I try to test the error window by entering in invalid info, the applet itself shows nothing but the command prompt window pops up and lists errors from Java. Anyhow, here is the method I was told to use to fix it.
    private static boolean validate(JTextField in)
              String inText = in.getText();
              char[] charInput = inText.toCharArray();
              for(int i = 0; i < charInput.length; i++)
                   int asciiVal = (int)charInput;
              if((asciiVal >= 48 && asciiVal <= 57) || asciiVal == 46)
              else
                   JOptionPane.showMessageDialog(null, "Invalid Character, Please Use Numeric Values Only");
                   return false;
                   return true;
         }My Instructor told me to try the following, but I still can't get it to work.String content = textField.getText();
    if (content.length() != 0) {       
    try {          Integer.parseInt(content);  
    } catch (NumberFormatException nfe) {}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problem with Listeners/ requestFocus()

    Hello,
    I am new to Java (started learning two months back), There is a problem with the requestFocus() in the focusListener. The program does not return the focus to the object indicated in the requestFocus but it shows multiple cusors!!
    The faculity at the institute where I am learning could not rectify the error.
    Is the error because of the myMethod() which I am using. I had made this method to prove to my professor that we can reduce the code drastically while using the gridbaglayout.
    The code which I had written is as under:
    // file name ShopperApplet.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ShopperApplet extends JApplet implements ActionListener, FocusListener,Runnable
         //static JPanel sP;
         //static JPanel oP;
         JTabbedPane tabbedPane = new JTabbedPane();
         JPanel sP;
         JPanel oP;
         JPanel pwd = new JPanel();
         // Layout Decleration of oP
         GridBagLayout ordL = new GridBagLayout();
         GridBagConstraints ordC = new GridBagConstraints();
         // Layout Decleration of sP
         FlowLayout flow = new FlowLayout();
         // Variables of sP
              JTextField textShopperId;
              JPasswordField textPassword;
              JTextField textFirstName ;
              JTextField textLastName ;
              JTextField textEmailId ;
              JTextField textAddress ;
              JComboBox comboCity ;
              JTextField textState ;
              JTextField textCountryId ;
              JTextField textZipCode ;
              JTextField textPhone ;
              JTextField textCreditCardNo ;
              JRadioButton rbVisa;
              JRadioButton rbMaster;
              JRadioButton rbAmEx;
              ButtonGroup BGccType;
              //JComboBox comboCreditCardType;
              //JTextField textExperyDate;
              JComboBox cmbDt;
              JComboBox cmbMth;
              JComboBox cmbYear;
              JButton btnSubmit;
              JButton btnReset;          
         // Variables of oP
              // Variable Decleration od oP
              JTextField txtOrderNo;
              JTextField txtToyId;
              JTextField txtQty;
              JRadioButton rbYes;     
              JRadioButton rbNo;
              ButtonGroup bgGiftWrap;
              JComboBox cmbWrapperId;
              JTextField txtMsg;
              JTextField txtToyCost;
              JButton btnOSubmit;
              JButton btnOReset;     
         // Variables of pwd
              JTextField txtShopperId;
              JPasswordField txtPassword;
              JButton btnPSubmit;
              JButton btnPReset;     
              JButton btnPNew;
              JButton btnPLogoff;
              JLabel lblN, lblN1;     
              Thread t,t1;
         Font TNR = new Font("Times New Roman",1,15);
         Font arial = new Font("Arial",2,15);
         public void sPDet()
              //Variable Decleration of sP
              textShopperId = new JTextField(6);
              textPassword = new JPasswordField(4);
              textPassword.addFocusListener(this);
              //textPassword = new JTextField(4);
              textPassword.setEchoChar('*');
              textFirstName = new JTextField(20);
              textLastName = new JTextField(20);
              textEmailId = new JTextField(25);
              textAddress = new JTextField(20);
              String cityList[] = {"New Delhi", "Mumbai", "Calcutta", "Hyderabad"};
              comboCity = new JComboBox(cityList);
              comboCity.setEditable(true);
              textState = new JTextField(30);
              textCountryId = new JTextField(25);
              textZipCode = new JTextField(6);
              textPhone = new JTextField(25);
              textCreditCardNo = new JTextField(25);
              String cardTypes[] = {"Visa", "Master Card", "American Express"};
              //comboCreditCardType = new JComboBox(cardTypes);
              rbVisa = new JRadioButton("Visa");
              rbMaster = new JRadioButton("Master Card");
              rbAmEx = new JRadioButton("American Express");
              BGccType = new ButtonGroup();
              BGccType.add(rbVisa);
              BGccType.add(rbMaster);
              BGccType.add(rbAmEx);
              String stDt[] = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
              String stMth[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
              String stYear[] = {"2001","2002","2003","2004","2005","2006","2007","2008","2009","2010"};
              cmbDt = new JComboBox(stDt);
              cmbMth = new JComboBox(stMth);
              cmbYear = new JComboBox(stYear);
              //textExperyDate = new JTextField(10);
              btnSubmit = new JButton("Submit");
              btnReset = new JButton("Reset");
              // Adding Layout Controls
              sP.setLayout(ordL);
              sP.setBackground(Color.green);
              myLayout(textShopperId,3,1,sP,"FM","Shopper Id");
              myLayout(textPassword,3,2,sP,"FM","Password");
              myLayout(textFirstName,3,3,sP,"FM","First Name") ;
              myLayout(textLastName,3,4,sP,"FM","Last Name") ;
              myLayout(textEmailId,3,5,sP,"FM","E-Mail Id") ;
              myLayout(textAddress,3,6,sP,"FM", "Address") ;
              myLayout(comboCity,3,7,sP,"FM","City") ;
              myLayout(textState,3,8,sP,"FM","State") ;
              myLayout(textCountryId,3,9,sP,"FM","Country") ;
              myLayout(textZipCode,3,10,sP,"FM","Zip Code") ;
              myLayout(textPhone,3,11,sP,"FM","Phone") ;
              myLayout(textCreditCardNo,3,12,sP,"FM","Credit Card No.") ;
              //myLayout(rbVisa,3,13,sP);
              JPanel newPanel = new JPanel();
              newPanel.add(rbVisa);
              newPanel.add(rbMaster);
              newPanel.add(rbAmEx);
              myLayout(newPanel,3,13,sP,"FM","Credit Card Type");
              //myLayout(rbMaster,4,13);
              //myLayout(rbAmEx,5,13);
              JPanel newPanel1 = new JPanel();
              newPanel1.add(cmbDt);
              newPanel1.add(cmbMth);
              newPanel1.add(cmbYear);
              myLayout(newPanel1,3,14,sP,"FM","Expiry Date");
              //myLayout(textExperyDate,3,14,sP,"FM");
              myLayout(btnSubmit,1,17,sP,"AL","Submit");
              myLayout(btnReset,3,17,sP,"AL","Reset");          
         public void oPDet()
              txtOrderNo = new JTextField(10);
              txtToyId = new JTextField(10);
              txtQty = new JTextField(10);
              rbYes = new JRadioButton("Yes");
              rbNo = new JRadioButton("No");
              bgGiftWrap = new ButtonGroup();
              bgGiftWrap.add(rbYes);
              bgGiftWrap.add(rbNo);
              String wrapperTypes[] = {"Blue Stripes", "Red Checks", "Green Crosses","Yellow Circles", "Red & Purple Stripes"};
              cmbWrapperId = new JComboBox(wrapperTypes);
              txtMsg = new JTextField(10);
              txtToyCost = new JTextField(10);
              btnOSubmit = new JButton("Submit");
              btnOReset = new JButton("Reset");
              // Adding Controls to oP
              oP.setLayout(ordL);
              oP.setBackground(Color.yellow);
              myLayout(txtOrderNo,3,1,oP,"FM","Order No.");
              myLayout(txtToyId,3,2,oP,"FM","Toy Id");
              myLayout(txtQty,3,3,oP,"FM","Quantity");
              myLayout(rbYes,3,4,oP,"M");
              myLayout(rbNo,4,4,oP,"M");
              myLayout(cmbWrapperId,3,5,oP,"M","Wrapper Id");
              myLayout(txtMsg,3,6,oP,"FM","Message");
              myLayout(txtToyCost,3,7,oP,"FM","Toy Cost");
              myLayout(btnOSubmit,1,8,oP,"AL","Submit");
              myLayout(btnOReset,3,8,oP,"AL","Reset");          
         public void pwdDet()
              pwd.setLayout(ordL);
              pwd.setBackground(Color.green);
              t = new Thread(this);
              t.start();
              t1 = new Thread(this);
              t1.start();
              lblN = new JLabel("");
              lblN1 = new JLabel("");
              txtShopperId = new JTextField(10);
              txtPassword = new JPasswordField(10);
              btnPSubmit = new JButton("Submit") ;
              btnPReset = new JButton("Reset");     
              btnPNew = new JButton("New Member");
              btnPLogoff = new JButton("Log Off");
              pwd.setLayout(ordL);
              pwd.setBackground(Color.yellow);
              myLayout(lblN,3,7,pwd);
              myLayout(lblN1,3,8,pwd);
              myLayout(txtShopperId,3,1,pwd,"FM","Shopper Id.");
              myLayout(txtPassword,3,2,pwd,"FM","Password");
              myLayout(btnPSubmit,2,4,pwd,"AL","Submit");
              myLayout(btnPReset,3,4,pwd,"AL","Reset");          
              myLayout(btnPNew,2,5,pwd,"AL","New");
              myLayout(btnPLogoff,3,5,pwd,"AL","Log Off");
         public void run()
              int ctr =0;
              String ili[] = {"India","is","a","Great","Country"};
              int ctr1 = 0;
              String iib[] = {"India","is","the","Best"};
              Thread myThread = Thread.currentThread();
              if (myThread == t)
                   while (t != null)
                        lblN.setText(ili[ctr]);
                        ctr++;
                        if (ctr >=5) ctr=0;
                        try
                             t.sleep(500);
                        catch(InterruptedException e)
                             showStatus("India is a great Country has been interrupter");
              else
                   while (t1 != null)
                        lblN1.setText(iib[ctr1]);
                        ctr1++;
                        if (ctr1 >=4) ctr1=0;
                        try
                             t1.sleep(1000);
                        catch(InterruptedException e)
                             showStatus("India is the best has been interrupter");
         public void myLayout(JComponent aObj, int x, int y, JPanel aPanel,String aListener,String toolTip)
              ordC.anchor=GridBagConstraints.NORTHWEST;
              JLabel aLabel = new JLabel(toolTip);
              ordC.gridx = x-1;
              ordC.gridy = y;
              ordL.setConstraints(aLabel,ordC);
              aPanel.add(aLabel);
              aObj.setToolTipText("Enter "+toolTip+" here");
              aObj.setForeground(Color.red);
              aObj.setBackground(Color.green);
              if (aListener.indexOf("F")     != -1)
                   aObj.addFocusListener(this);
              //if (aListener.indexOf("M")     != -1)
                   //aObj.addMouseListener(this);
              aObj.setFont(TNR);
              ordC.gridx = x;
              ordC.gridy = y;
              ordL.setConstraints(aObj,ordC);
              aPanel.add(aObj);
         public void myLayout(JComponent aObj, int x, int y, JPanel aPanel,String aListener)
              ordC.anchor=GridBagConstraints.NORTHWEST;
              aObj.setForeground(Color.red);
              aObj.setBackground(Color.green);
              if (aListener.indexOf("F")     != -1)
                   aObj.addFocusListener(this);
              //if (aListener.indexOf("M")     != -1)
                   //aObj.addMouseListener(this);
              aObj.setFont(TNR);
              ordC.gridx = x;
              ordC.gridy = y;
              ordL.setConstraints(aObj,ordC);
              aPanel.add(aObj);
         public void myLayout(JButton aObj, int x, int y, JPanel aPanel,String aListener, String toolTip)
              aObj.setToolTipText(toolTip);
              ordC.anchor=GridBagConstraints.NORTHWEST;
              aObj.setForeground(Color.red);
              if (aListener.indexOf("F")     != -1)
                   aObj.addFocusListener(this);
              //if (aListener.indexOf("M")     != -1)
                   //aObj.addMouseListener(this);
              if (aListener.indexOf("A")     != -1)
                   aObj.addActionListener(this);
              aObj.setFont(TNR);
              ordC.gridx = x;
              ordC.gridy = y;
              ordL.setConstraints(aObj,ordC);
              aPanel.add(aObj);
         public void myLayout(JTextField aObj, int x, int y, JPanel aPanel,String aListener,String toolTip)
              ordC.anchor=GridBagConstraints.NORTHWEST;
              //aObj = new JTextField(10);
              JLabel aLabel = new JLabel(toolTip);
              ordC.gridx = x-1;
              ordC.gridy = y;
              ordL.setConstraints(aLabel,ordC);
              aPanel.add(aLabel);
              aObj.setToolTipText("Enter "+toolTip+" here");
              aObj.setForeground(Color.red);
              if (aListener.indexOf("F")     != -1)
                   aObj.addFocusListener(this);
              //if (aListener.indexOf("M")     != -1)
              //     aObj.addMouseListener(this);
              if (aListener.indexOf("A")     != -1)
                   aObj.addActionListener(this);
              aObj.setFont(TNR);
              ordC.gridx = x;
              ordC.gridy = y;
              ordL.setConstraints(aObj,ordC);
              aPanel.add(aObj);
         public void myLayout(JLabel aObj, int x, int y, JPanel aPanel)
              ordC.anchor=GridBagConstraints.SOUTH;
              aObj.setForeground(Color.blue);
              aObj.setFont(TNR);
              ordC.gridx = x;
              ordC.gridy = y;
              ordL.setConstraints(aObj,ordC);
              aPanel.add(aObj);
         public void init()
              getContentPane().add(tabbedPane);
              sP = new JPanel();
              sPDet();
              oP = new JPanel();
              oPDet();
              pwdDet();
              tabbedPane.addTab("Login",null,pwd,"Login");
              tabbedPane.addTab("Shopper",null,sP,"Shopper Details");
              tabbedPane.addTab("Order",null,oP,"Order Details");
              tabbedPane.setEnabledAt(2, false);
              tabbedPane.setEnabledAt(1, false);
         public void actionPerformed(ActionEvent e)
              Object obj = e.getSource();
              if (obj == btnSubmit)
                   if (validShopperId() == false) return;
                   if (validPassword() == false) return;
                   if (validFirstName() == false) return ;
                   if (validLastName() == false) return ;
                   if (validEmailId() == false) return;
                   if (validAddress() == false) return;
                   if (validState() == false) return;
                   if (validCountryId() == false) return;
                   if (validZipCode() == false) return;
                   if (validCreditCardNo() == false) return ;
                   resetShopper();
                   tabbedPane.setEnabledAt(1,false);
                   tabbedPane.setEnabledAt(2,false);
                   tabbedPane.setSelectedIndex(0);
                   // also can be written as tabbedPane.setSelectedComponent(pwd);
                   //tabbedPane.remove(sP);
              if (obj == btnReset)
                   resetShopper();
                   tabbedPane.setEnabledAt(2,false);
                   //textExperyDate.setText("");
              if (obj == btnOSubmit)
                   if (validOrderNo() == false) return;
                   if (validToyId() == false) return;
                   if (chkNullEntry(txtQty, "Quantity")) return ;
                   if (chkNullEntry(txtToyCost, "Toy Cost")) return ;
              if (obj == btnOReset)
                   resetOrder();
              if (obj == btnPSubmit)
                   if (validPShopperId() && validPPassword())
                        tabbedPane.setEnabledAt(2, true);
                        tabbedPane.setEnabledAt(1, false);
                        txtShopperId.setText("");
                        txtPassword.setText("");
                        resetPassword();
                        //tabbedPane.addTab("Order",null,oP,"Order Details");
              if (obj == btnPReset)
                   resetPassword();
                   tabbedPane.setEnabledAt(1, false);
                   tabbedPane.setEnabledAt(2, false);
              if (obj == btnPNew)
                   tabbedPane.setEnabledAt(1, true);
                   tabbedPane.setEnabledAt(2, false);
                   resetPassword();
                   tabbedPane.setSelectedComponent(sP);
                   //tabbedPane.addTab("Shopper",null,sP,"Shopper Details");          
              if (obj == btnPLogoff)
                   tabbedPane.setEnabledAt(2, false);
                   tabbedPane.setEnabledAt(1, false);
                   resetPassword();
         public void focusGained(FocusEvent fe)
              //Object aObj = fe.getSource();
              //showStatus("Current Object is "+aObj);
         public void resetPassword()
              txtShopperId.setText("");
              txtPassword.setText("");
         public void resetShopper()
                   textShopperId.setText("");
                   textPassword.setText("");
                   textFirstName.setText("") ;
                   textLastName.setText("") ;
                   textEmailId.setText("") ;
                   textAddress.setText("") ;
                   textState.setText("") ;
                   textCountryId.setText("") ;
                   textZipCode.setText("") ;
                   textPhone.setText("") ;
                   textCreditCardNo.setText("") ;
         public void resetOrder()
              txtOrderNo.setText("");
              txtToyId.setText("");
              txtQty.setText("") ;
              txtToyCost.setText("") ;
              txtMsg.setText("") ;
         public void focusLost(FocusEvent fe)
              try{
                   Object obj = fe.getSource();
                   if (obj == textShopperId &&     validShopperId() == false)
                        //textShopperId.requestFocus();
                        return;
                   if (obj == textPassword && validPassword() == false)
                        //textPassword.requestFocus();
                        return;
                   if (obj == textFirstName && validFirstName() == false)
                        //textFirstName.requestFocus();
                        return;
                   if (obj == textEmailId && validEmailId() == false)
                        //textEmailId.requestFocus();
                        return;
                   if (obj == txtOrderNo && validOrderNo() == false)
                        //txtOrderNo.requestFocus();
                        return;
                   if (obj == txtToyId && validToyId() == false);
                        //txtToyId.requestFocus();
                        return;
              catch(Exception e)
                   showStatus("error in LostFocus() Method");
         public boolean validShopperId()
              if (chkNullEntry(textShopperId,"Shopper Id")) return false;
              return true;
         public boolean validPassword()
              if (chkNullEntry(textPassword,"Password")) return false;
              return true;
         public boolean validFirstName()
              if (chkNullEntry(textFirstName,"First Name")) return false;
              return true;
         public boolean validLastName()
              if (chkNullEntry(textLastName,"Last Name")) return false;
              return true;
         public boolean validAddress()
              if (chkNullEntry(textAddress,"Address")) return false;
              return true;
         public boolean validState()
              if (chkNullEntry(textState,"State")) return false;
              return true;
         public boolean validCountryId()
              if (chkNullEntry(textCountryId,"Country")) return false;
              return true;
         public boolean validZipCode()
              if (chkNullEntry(textZipCode,"Postal Code")) return false;
              return true;
         public boolean validCreditCardNo()
              if (chkNullEntry(textCreditCardNo,"Credit Card No.")) return false;
              return true;
         public boolean validEmailId()
              if (chkNullEntry(textEmailId,"Email Address")) return false;
              String s1 = textEmailId.getText();
              int abc = s1.indexOf("@");
              if (abc == -1 || abc == 0 || abc == (s1.length()-1))
                   JOptionPane.showMessageDialog(sP,"Invalid Email Address","Error Message",JOptionPane.ERROR_MESSAGE);
                   //textEmailId.requestFocus();
                   return false;
              return true;
         public boolean validOrderNo()
              if (chkNullEntry(txtOrderNo,"Order No.")) return false;
              return true;
         public boolean validToyId()
              if (chkNullEntry(txtToyId,"Toy Id")) return false;
              return true;
         public boolean chkNullEntry(JTextField aObj,String sDef)
              String s1 = aObj.getText();
              if (s1.length() ==0)
                   try
                        JOptionPane.showMessageDialog(sP,sDef+" cannot be left blank","Error Message",JOptionPane.ERROR_MESSAGE);
                        //showStatus(sDef+" cannot be left blank");
                        // nbvvvv vcz     z111111eeeefgggggggggg aObj.requestFocus();
                   catch(Exception e)
                        showStatus("Error in chkNullEntry() method");
                   return true ;
              else
                   return false;
         public boolean validPShopperId()
              if (chkNullEntry(txtShopperId,"Shopper Id")) return false;
              return true;
         public boolean validPPassword()
              if (chkNullEntry(txtPassword,"Password")) return false;
              return true;
    // end of code.

    Would it not be acceptable to check that each field has a value when Submit is pressed. If a field is found with no data then display the error message and return the focus to the empty field. This would solve the multiple cursors problem as you would not need any focusLost handler code.
    If this is entirely out of the question then you will have to override some of the FocusManager methods to prevent the JVM from handling focus for you :
    FocusManager.setCurrentManager(new DefaultFocusManager() {
      // Override FocusManager methods here.
    });Ronny.

  • Creation of an applet JApplet in a desktop JDesktopPane

    how its posible to load from a jar file an applet which come from package my.package.myclass of the jar file.
    next i want to put it in a JInternalFrame and put this desktop frame in a JDesktopPane.
    indeed i can move the applet around with other applets in a little window!
    here's the code of the desktop_panel.javapackage kevin_shell;
    import kevin_shell.Kdemos.*;
    import java.awt.*;
    import java.awt.event.*;
    import java2d.MemoryMonitor;
    //import java2d.demos.Lines.*;
    import javax.swing.*;
    import javax.swing.border.BevelBorder;
    import javax.swing.border.Border;
    import com.l2fprod.gui.plaf.skin.Skin;
    import com.l2fprod.gui.plaf.skin.SkinLookAndFeel;
    public class desktop_panel extends JPanel {
    JInternalFrame win_info = new JInternalFrame();
    public void killme(KDemo demo) {
    demo = null;
    public void view_image(String file) {
    thread_load_cube load = new thread_load_cube(file);
    load.start();
    JPanel jPanel2 = new JPanel();
    JDesktopPane pan_workspace = new JDesktopPane();
    public void paint(Graphics p) {
    p.setColor(Color.blue);
    p.fillRect(0, 0, 1000, 1000);
    p.setColor(Color.red);
    p.drawString("kevin OS", 10, 10);
    super.paint(p);
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel3 = new JPanel();
    JButton jButton1 = new JButton();
    JInternalFrame win_memory = new JInternalFrame();
    JInternalFrame win_terminal = new JInternalFrame();
    MemoryMonitor win_mem = new MemoryMonitor();
    KClock win_perf = new KClock();
    JPanel jPanel4 = new JPanel();
    JLabel jLabel1 = new JLabel();
    JButton jButton2 = new JButton();
    JLabel jLabel6 = new JLabel();
    JLabel jLabel4 = new JLabel();
    JButton but_collect = new JButton();
    JButton but_refresh = new JButton();
    JTextField nb_free = new JTextField();
    Border border1;
    Border border2;
    JLabel jLabel2 = new JLabel();
    JTextField ed_jdk_path = new JTextField();
    JTextField nb_total = new JTextField();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel5 = new JLabel();
    bean_clock bean_clock1 = new bean_clock();
    JPanel jPanel5 = new JPanel();
    JPanel jPanel1 = new JPanel();
    JTabbedPane tabber = new JTabbedPane();
    BorderLayout borderLayout2 = new BorderLayout();
    JList list1 = new JList();
    JList list_system = new JList();
    JList list3 = new JList();
    JButton jButton3 = new JButton();
    JButton jButton4 = new JButton();
    JButton jButton5 = new JButton();
    JButton jButton6 = new JButton();
    test_applet Itest_applet = new test_applet();
    JButton jButton7 = new JButton();
    public desktop_panel() {
    try {
    jbInit();
    System.out.println("initializing desk");
    bean_clock1.setLocation(0, 0);
    bean_clock1.setSize(win_info.getPreferredSize());
    //bean_clock1.start();
    pan_workspace.add(win_info);
    win_info.show();
    win_info.setLocation(0, 0);
    win_info.setSize(win_info.getPreferredSize());
    //Class bruno=java.lang.ClassLoader.getSystemClassLoader().loadClass("demo_cube");
    //Object b=bruno.newInstance();
    pan_workspace.add(win_memory);
    win_memory.show();
    win_memory.setSize(win_memory.getPreferredSize());
    pan_workspace.add(win_terminal);
    win_terminal.show();
    win_terminal.setSize(win_terminal.getPreferredSize());
    pan_workspace.add(win_mem);
    win_mem.setVisible(true);
    win_mem.setSize(win_mem.getPreferredSize());
    pan_workspace.add(win_perf);
    win_perf.setVisible(true);
    win_perf.setSize(100, 100);
    win_perf.setLocation(400, 400);
    win_perf.startClock();
    //list_system.add("welcome to kevin os");
    //tabber.add(list_system);
    tabber.add(list1);
    tabber.add(list3);
    win_terminal.getContentPane().add(tabber, BorderLayout.CENTER);
    win_terminal.setSize(300, 300);
    win_terminal.setResizable(true);
    win_terminal.setLocation(400, 400);
    System.out.println("ok");
    } catch (Exception e) {
    e.printStackTrace();
    class thread_load_cube extends Thread {
    String file;
    thread_load_cube() {
    file = "pics/babe1.jpg";
    thread_load_cube(String f) {
    file = f;
    //win_cube
    public void run() {
    try {
    System.out.println("cube loading");
    Class demo = java.lang.ClassLoader.getSystemClassLoader().
    loadClass("kevin_shell.Kdemos.demo_cube");
    KDemo win_cube = (KDemo) demo.newInstance();
    //list_system.add("win cube (loading....)");
    java.net.URL stoneURL = main_win.class.getResource(file);
    java.net.URL skyURL = main_win.class.getResource(
    "pics/babe2.jpg");
    //win_cube=new demo_cube();
    win_cube.set_parameters(stoneURL, skyURL);
    //pan_workspace.add(win_cube);
    win_cube.show();
    win_cube.setLocation(300, 300);
    win_cube.setSize(300, 300);
    win_cube.setResizable(true);
    win_cube.setTitle("java 3d cube");
    win_cube.setIconifiable(true);
    win_cube.init();
    win_cube.setClosable(true);
    System.out.println("ok");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    System.out.println("problem with class");
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    System.out.println("acces problem");
    } catch (InstantiationException e) {
    e.printStackTrace();
    System.out.println("instance");
    class thread_load_j3d extends Thread {
    public void run() {
    //list_system.add("j3d test loading...");
    //kev
    try {
    Class demo = java.lang.ClassLoader.getSystemClassLoader().
    loadClass("kevin_shell.Kdemos.demo_j3d");
    KDemo win = (KDemo) demo.newInstance();
    //pan_workspace.add(win);
    win.show();
    win.setLocation(300, 300);
    win.setSize(300, 300);
    win.setResizable(true);
    win.setTitle("j3d test");
    win.setIconifiable(true);
    win.init();
    win.setClosable(true);
    System.out.println("ok");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    System.out.println("problem with class");
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    System.out.println("acces problem");
    } catch (InstantiationException e) {
    e.printStackTrace();
    System.out.println("instance");
    private void jbInit() throws Exception {
    border1 = BorderFactory.createMatteBorder(4, 4, 4, 4,
    new Color(91, 91, 91));
    border2 = BorderFactory.createBevelBorder(BevelBorder.RAISED,
    Color.white, Color.white,
    new Color(153, 153, 204),
    new Color(153, 153, 204));
    jButton2.setBackground(Color.white);
    jButton2.setBorder(BorderFactory.createLineBorder(Color.black));
    jButton2.setPreferredSize(new Dimension(70, 70));
    //jButton2.setIcon(new ImageIcon(desktop_panel.class.getResource("icons/on_kevin.gif")));
    jButton2.setMargin(new Insets(0, 0, 0, 0));
    jButton2.setBounds(new Rectangle(9, 6, 52, 54));
    jLabel1.setFont(new java.awt.Font("Dialog", 1, 70));
    jLabel1.setForeground(SystemColor.desktop);
    jLabel1.setText("kevin os 1.0");
    jLabel1.setBounds(new Rectangle(66, 6, 255, 22));
    this.setLayout(borderLayout1);
    this.setBackground(UIManager.getColor("EditorPane.selectionBackground"));
    jPanel2.setLayout(null);
    jPanel2.setBackground(UIManager.getColor(
    "InternalFrame.activeTitleBackground"));
    jPanel2.setMaximumSize(new Dimension(100, 100));
    jPanel2.setMinimumSize(new Dimension(100, 100));
    jPanel2.setPreferredSize(new Dimension(100, 100));
    jPanel3.setBackground(new Color(255, 231, 0));
    jPanel3.setPreferredSize(new Dimension(60, 10));
    jButton1.setBackground(Color.white);
    jButton1.setBorder(BorderFactory.createLineBorder(Color.black));
    jButton1.setPreferredSize(new Dimension(50, 50));
    //jButton1.setIcon(new ImageIcon(desktop_panel.class.getResource("icons/info.gif")));
    jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton1_mouseClicked(e);
    pan_workspace.setBackground(UIManager.getColor(
    "List.selectionBackground"));
    pan_workspace.setOpaque(false);
    pan_workspace.setAlignmentX((float) 0.0);
    pan_workspace.setAlignmentY((float) 0.0);
    pan_workspace.setLayout(null);
    win_memory.setToolTipText("");
    win_memory.getContentPane().setBackground(SystemColor.controlDkShadow);
    win_memory.setTitle("memory");
    win_memory.setBorder(border2);
    win_memory.setIconifiable(true);
    win_memory.setNormalBounds(new Rectangle(10, 10, 381, 254));
    win_memory.setPreferredSize(new Dimension(381, 254));
    win_memory.setMinimumSize(new Dimension(381, 254));
    win_info.setFrameIcon(null);
    win_info.setPreferredSize(new Dimension(269, 230));
    win_info.setMinimumSize(new Dimension(269, 230));
    win_info.setBorder(border2);
    win_info.getContentPane().setBackground(UIManager.getColor(
    "CheckBoxMenuItem.selectionBackground"));
    win_info.setMaximumSize(new Dimension(100, 100));
    win_info.setResizable(true);
    win_info.setIconifiable(true);
    win_info.setTitle("kevin OS info");
    but_collect.setBackground(Color.orange);
    but_collect.setText("garbage collector");
    but_collect.setBounds(new Rectangle(13, 114, 162, 31));
    but_collect.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    but_collect_mouseClicked(e);
    but_refresh.setText("refresh");
    but_refresh.setBounds(new Rectangle(11, 150, 162, 32));
    but_refresh.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    but_refresh_mouseClicked(e);
    nb_free.setBackground(Color.white);
    nb_free.setDisabledTextColor(Color.white);
    nb_free.setEditable(false);
    nb_free.setBounds(new Rectangle(107, 40, 108, 22));
    jPanel4.setBackground(UIManager.getColor(
    "InternalFrame.activeTitleBackground"));
    jLabel2.setBackground(Color.pink);
    jLabel2.setFont(new java.awt.Font("Dialog", 1, 50));
    jLabel2.setForeground(Color.red);
    jLabel2.setText("-OS-");
    jLabel2.setBounds(new Rectangle(98, 12, 139, 52));
    ed_jdk_path.setBackground(Color.white);
    ed_jdk_path.setDisabledTextColor(Color.white);
    ed_jdk_path.setEditable(false);
    ed_jdk_path.setBounds(new Rectangle(104, 14, 190, 22));
    nb_total.setBackground(Color.white);
    nb_total.setDisabledTextColor(Color.white);
    nb_total.setEditable(false);
    nb_total.setBounds(new Rectangle(228, 40, 108, 22));
    jLabel3.setToolTipText("");
    jLabel3.setText("free");
    jLabel3.setBounds(new Rectangle(106, 70, 112, 16));
    jLabel5.setBounds(new Rectangle(228, 70, 112, 16));
    jLabel5.setText("total");
    jLabel5.setToolTipText("");
    win_terminal.setTitle("terminal");
    jPanel5.setLayout(borderLayout2);
    jButton3.setPreferredSize(new Dimension(50, 27));
    jButton3.setText("cube");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton3_actionPerformed(e);
    jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton3_mouseClicked(e);
    jButton4.setText("test");
    jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton4_mouseClicked(e);
    jButton5.setText("skin cool");
    jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton5_mouseClicked(e);
    jButton6.setText("skin xp");
    jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jButton6_mouseClicked(e);
    jButton7.setText("test applet");
    jButton7.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton7_actionPerformed(e);
    win_memory.getContentPane().add(jPanel4, BorderLayout.CENTER);
    jPanel4.setLayout(null);
    jPanel4.setMinimumSize(new Dimension(100, 100));
    jPanel4.setPreferredSize(new Dimension(100, 100));
    jLabel6.setText("java memory");
    jLabel6.setBounds(new Rectangle(16, 40, 78, 18));
    jLabel4.setText("jdk path");
    jLabel4.setBounds(new Rectangle(18, 16, 76, 18));
    this.add(jPanel3, BorderLayout.WEST);
    jPanel3.add(jButton7);
    jPanel3.add(jButton1, null);
    jPanel3.add(jButton3, null);
    jPanel3.add(jButton4, null);
    jPanel3.add(jButton5, null);
    jPanel3.add(jButton6, null);
    this.add(pan_workspace, java.awt.BorderLayout.CENTER);
    jPanel4.add(jLabel4, null);
    jPanel4.add(jLabel6, null);
    jPanel4.add(but_collect, null);
    jPanel4.add(ed_jdk_path, null);
    jPanel4.add(nb_free, null);
    jPanel4.add(nb_total, null);
    jPanel4.add(but_refresh, null);
    jPanel4.add(jLabel3, null);
    jPanel4.add(jLabel5, null);
    win_info.getContentPane().add(jPanel2, BorderLayout.CENTER);
    jPanel2.add(jButton2, null);
    jPanel2.add(jLabel1, null);
    jPanel2.add(jLabel2, null);
    tabber.add(list1, "list1");
    tabber.add(list_system, "list_system");
    tabber.add(list3, "list3");
    void but_refresh_mouseClicked(MouseEvent e) {
    nb_free.setText(String.valueOf(java.lang.Runtime.getRuntime().
    freeMemory()));
    nb_total.setText(String.valueOf(java.lang.Runtime.getRuntime().
    totalMemory()));
    void jButton1_mouseClicked(MouseEvent e) {
    win_info.show();
    win_info.setLocation(0, 0);
    //win_info.setSize(100,100);
    void but_collect_mouseClicked(MouseEvent e) {
    java.lang.Runtime.getRuntime().gc();
    but_refresh_mouseClicked(e);
    //list_system.add("collecting memory");
    void jButton3_mouseClicked(MouseEvent e) {
    //win_cube.begin_anim();
    void jButton4_mouseClicked(MouseEvent e) {
    thread_load_j3d load = new thread_load_j3d();
    load.start();
    void jButton6_mouseClicked(MouseEvent e) {
    try {
    Skin skin = null;
    //windows xp
    skin = SkinLookAndFeel.loadThemePack("skins/BeOS-theme.jar");
    // set the skin
    SkinLookAndFeel.setSkin(skin);
    // ask Swing to use Skin Look And Feel
    UIManager.setLookAndFeel(
    "com.l2fprod.gui.plaf.skin.SkinLookAndFeel");
    SwingUtilities.updateComponentTreeUI(this);
    this.validate();
    this.updateUI();
    } catch (Exception er) {
    System.out.println("Failed loading L&F: ");
    er.printStackTrace();
    void jButton5_mouseClicked(MouseEvent e) {
    try {
    Skin skin = null;
    skin = SkinLookAndFeel.loadThemePack("skins/themepack.zip");
    // set the skin
    SkinLookAndFeel.setSkin(skin);
    // ask Swing to use Skin Look And Feel
    UIManager.setLookAndFeel(
    "com.l2fprod.gui.plaf.skin.SkinLookAndFeel");
    } catch (Exception er) {
    er.printStackTrace();
    void jButton3_actionPerformed(ActionEvent e) {
    thread_load_cube load = new thread_load_cube();
    load.start();
    public void jButton7_actionPerformed(ActionEvent e) {
    JApplet applet=null;
    frame_applet frame=null;
    try{
    //ExtClassLoader ecl = new ExtClassLoader("/home/kevinet/CODE/JAVA/jlguiapplet2.3.1-selfsigned/lib/jlguiapplet2.3.jar");
    //Class demo = ecl.loadClass("javazoom.jlgui.player.amp.PlayerApplet");
    Class demo = java.lang.ClassLoader.getSystemClassLoader().loadClass("kevin_shell.Kdemos.test_applet");
    applet = (JApplet) demo.newInstance();
    frame=new frame_applet(applet);
    } catch (ClassNotFoundException cnfe) {
    cnfe.printStackTrace();
    System.out.println("problem with class");
    catch (IllegalAccessException iae) {
    iae.printStackTrace();
    System.out.println("acces problem");
    catch (InstantiationException ie) {
    ie.printStackTrace();
    System.out.println("instance");
    System.out.println("hello");
    pan_workspace.add(frame);
    applet.init();
    //applet.setLocation(0,0);
    applet.start();
    frame.setVisible(true);
    frame.show();
    frame.setLocation(300, 300);
    frame.setSize(300, 300);
    frame.setResizable(true);
    frame.setTitle("test applet");
    frame.setIconifiable(true);
    frame.setClosable(true);
    }

    What about calling getLocation on the applet itself?
    Otherwise, if you are using Swing, you can try (where "this" is the applet object):
    javax.swing.SwingUtilities.getWindowAncestor(this).getLocation();
    or
    javax.swing.SwingUtilities.convertPointToScreen(this.getLocation(), this);
    The latter should work, at least.

  • Why does this applet (with an audio clip) fail to load in a browser?

    Hello Java Experts.
    I am able to compile and run the applet in an IDE. The problem lies when I attempt to run the applet through a browser (such as Internet Explorer, Firefox, etc.). The entire applet fails to load (in the browser) when it includes code pertaining to audio clips, but works fine when it does not contain audio clip related code.
    Here is a Short, Self Contained, Compilable, Example that illustrates my problem:
    import javax.swing.*;  //  Required libraries
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class Music extends JApplet  //  Music class is a subclass of the JApplet class
        AudioClip music;
        public void init ()
            music = getAudioClip (getCodeBase (), "sample.wav");  //  You may use your own audio file
            music.loop();
        public void paint (Graphics g)
            g.setColor (Color.blue); 
            g.fillRect (0, 0, 800, 600);  //  THIS RECTANGLE IS NOT DRAWN (this is my test to see if the applet loads in the browser)
    }Please try to run this applet in a browser so that you can point me to my mistake(s).
    Thanks for the help in advance.

    >
    Here is a Short, Self Contained, Compilable, Example that illustrates my problem:>The 'example' part of it, fails to manifest here. Using that exact code, I was able to see a blue rectangle in both AppletViewer and FF. You might try..
    1) Configuring the Java Console to open for applets by default - look in it for error messages.
    2) Change the name of the WAV to something that definitely +does not exist+ at the code base. (That would most closely replicate my own testing experience - since there is no WAV available here).

  • JTextField and JApplet

    How can I have the JTextField as defined below to get the cursor (Focus), when the Applet starts (the requestFocus method is not working)?
    import javax.swing.*;
    import java.awt.*;
    public class MyFocusJApplet extends JApplet {
         JTextField     myTextField = new JTextField(20);
         public void init() {
              getContentPane().setLayout(new FlowLayout());
              getContentPane().add(myTextField);
              myTextField.requestFocus();
         public void start() {
              myTextField.requestFocus();
    }

    I searhed the forums and when modified my start method as:
         public void start() {
              SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                             myTextField.requestFocus();
    I got the required results!
    But I am not able to understand the above :-(

  • Netbeans nightmare Converting a JFrame  class to a JApplet Class

    Hello im not exactly new to java but im having problems getting my applets to work when i try other peoples example applets they always work but mine never seem to. here is what i am doing i wrote a card game in VB6 long story short i completely rewrote it in java because only ie supports ActiveX.
    It works awesome as a stand alone App whilst in Jframe and with a main() sub.
    I tried about 15 tutorials on how to convert a jframe to a applet with no success i always got errors and applet never loaded in browser.
    then i found these tips on how to do it "really easy" of course when my applet loads and im not sure it even really does i get nothing but a grey box i never seem my components a bunch of jlabels with icons loaded that look like card images it all looks great in the design tab of NetBeans. I never see any of the controls in browser. These are the links to the two tutorials that spawned my trying this. http://forums.java.net/jive/thread.jspa?threadID=57965&tstart=0 http://forums.java.net/jive/thread.jspa?threadID=57965&tstart=0
    well to quote this guy it feels like its going to take 100 years to figure this out google has a million links to junk when i try searches and sun has no great help for searching either on their documentation. my program is rediculously low tech and i cant seem to get it to do anything or work at all as an applet.
    my class looks like this: i removed all the constructor code as it was making post too long my applet shows up normal in the preview window of Netbenas but just a grey square of browser not sure whats wrong please someone help me.. Thanks You
    import java.util.Random;
    public class AcesKingsJApplet extends javax.swing.JApplet {
    /** Initializes the applet AcesKingsJApplet */
    public void init() {
    try {
    java.awt.EventQueue.invokeAndWait(new Runnable() {
    public void run() {
    initComponents();
    System.out.println("InitCOmpleted");
    // NewGame(1);
    } catch (Exception ex) {
    ex.printStackTrace();
    public void TableCardClick(int arg1){
    public void DiscardPileClick(int arg1){
    public void PerformUndoAction(){
    public void NewGame(int arg1){
    //new game code here
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel49;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel50;
    private javax.swing.JLabel jLabel51;
    private javax.swing.JLabel jLabel52;
    private javax.swing.JLabel jLabel53;
    private javax.swing.JLabel jLabel54;
    private javax.swing.JLabel jLabel55;
    private javax.swing.JLabel jLabel56;
    private javax.swing.JLabel jLabel58;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel60;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration
    int tableCardIndex = 99; //array only cause it has to be or game fails
    int discardPileIndex = 99;
    int[] cardDeckArray = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54};
    int[] cardDeckArrayPlayed = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
    //int[] precheckarg1;
    boolean GoAheadWithPlay;
    int gameUndoCount;
    int gamePlayCount;
    int gameCurrentRound = 1;
    int cardPointValue;
    int discardCardValue;
    int tableCardValue;
    int tableCardsRemaining = 35;
    int discardPileCards;
    int currentDiscardPileCard;
    int playerScore;
    // loss checking variables
    int badPlaysCount = 0;
    // variables for undo related activity below
    int[] undogamePlayCount = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int[] undodiscardPileCards = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int[] undocurrentDiscardPileCard = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int[] undoMethod = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int[] undoTableCard ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int[] undoDiscardCard ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    //end undo variable collection
    }

    You shouldn't start a new thread when you've already created a recent one with the exact same subject matter:
    [http://forums.sun.com/thread.jspa?threadID=5447497|http://forums.sun.com/thread.jspa?threadID=5447497]
    And my advice in the previous thread still stands. Put your program in a JPanel so it's environment-agnostic, then create two wrappers for standalone apps and applets.
    (or just use Java Web Start)
    Also your program has all sorts of other problems. This is terrible coding:
    private javax.swing.JLabel jLabel37;If you need lots of labels that all have the same meaning, put them in a collection. Give things meaningful names. etc.
    If that code was generated by Netbeans....then this is an example why you shouldn't use code generation tools...

  • PLAYING SOUND WITHOUT JApplet

    Hi there,
    I'm a new member in Java Developer forums, I hope that I'll be an effective member..
    for now I need help with java sound , multimedia
    I'm developing a program that part of it is to play array of sounds (Not JApplet) I tried to use the function AudioClip(getClass().getResources("soundName.wav"); but it works only with JApplet
    I want to play the sound without JApplet
    I found that there is a package called javax.swing.sound.*;
    but syntax error occured in my program.. that this package does not exist..
    Please help me..

    I am also having the same problem. I couldn't get sound to work with the applet based one. I have the below code, it compiles and when you run the program it runs the length of the audio file but there is no sound? Is there something missing?
    import sun.audio.*;    //import the sun.audio package
    import java.io.*;
    public class sound{
        public static void main (String args[])
              try
              InputStream in = new FileInputStream("cows2.au");
              AudioStream as = new AudioStream(in);
              AudioPlayer.player.start(as);
              AudioPlayer.player.stop(as);
              catch (Exception e)
                   System.out.println("Failed");
    } //end classMessage was edited by:
    Lisa_g

  • Japplet in jsp

    hi all
    i cant understand what wrong i m doing....i m annoyed very much
    my jsp page is in /UASEProject/Webcontent directory and applet class is in /UASEProject/Webcontent/registration directory and also its java file. jsp page is running successfully with the url htttp://localhost:9080/UASEProject/myjsp.jsp.but when i tried to access an japplet with the context specified below then in jsp at inserting area a red cross is displayed. the browser showing a message "applet not initited" and when i clicked in that red cross then the message was "applet loading failed".
    i m using rational application developer and it uses the server 'IBM web sphere application server v6.1'
    please.....check this out and give ur suggession.
    this is my jsp page
    <table>
       <tr>
          <td>
                     <jsp:plugin type="applet" code="NewJApplet.class" codebase="registration"
                   width="600" height="300">
         <jsp:fallback>Could not load applet...</jsp:fallback>
                   </jsp:plugin>
        </td>
      </tr>
    </table>i have tried with this also
    <table>
       <tr>
          <td>
                     <applet code="NewJApplet.class" codebase="registration"
                   width="600" height="300">
                   </applet>
        </td>
      </tr>
    </table>

    First, you shouldn't be calling paint with what you get from getGraphics(). You should update your state and call repaint() on the applet.
    You should probably load the images with the media tracker in the init() method anyway and ditch that thread thing. Unless they're really large images which you want to load asynchronously.
    Second, your onload init() thing in JS is kinda pointless. You might do that to have the applet trigger that method, but not onload, as that's right away. The browser shouldn't wait for the applet to start. to call onload. Anyway, an applet in a hidden DIV might not load at all anyway, in some browsers.

  • JApplet run in Debug mode but not in Run Mode in JDev3.1

    Hi All
    I am having a problem in running a JSP file which contain an JApplet. When I choose Run from the jDev, the applet seems to take a really long time to load and finally failed to load itself.
    However when i choose run from debug mode, the jsp run perfectly by displaying the applet.
    Any idea why?
    thanks for any help
    ka

    Hi All
    I am having a problem in running a JSP file which contain an JApplet. When I choose Run from the jDev, the applet seems to take a really long time to load and finally failed to load itself.
    However when i choose run from debug mode, the jsp run perfectly by displaying the applet.
    Any idea why?
    thanks for any help
    ka

  • Help JApplet not co-operating

    Hello.. i have the following code which is just like a pulldown menu in an applet on the web. it wokrs fine (u can test it ) but whenever the mouse leaves the button the menuitems remains. i want to implement a mouse or focus action so that when the mouse leaves the buttons or menuitems the menuitems disappear. try compiling and see it for ur self (it is error free).
    Thanks.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Test extends JApplet
         JButton button, button2;
         JPopupMenu jpop, jpop1;
         JMenuItem i1 [], i2 [];
         JMenu m2, m3, m4;
         String si1[] = {"Home", "Corporate Profile", "Our Mission", "Our Clients" , "Careers @ CT Limited"};
         String si2[] = {"Debit Card processing", "Credit Card processing", "Stored Value Card", "Card Personalization", "Card Printing", "Sales of POSs", "ATM Management"};
         String si3[] = {"Virtual Payment Processes", "e-Payment Solutions", "Proprietary Bank Card"};
         String si4[] = {"Biller Service Solutions", "Biller Service Provider", "Merchant Processing"};
    public void init ()
         getContentPane().setLayout (new FlowLayout());
         requestFocus();
         jpop = new JPopupMenu ();
         jpop1 = new JPopupMenu ();
         i1 = new JMenuItem [5];
         for (int i = 0; i < si1.length; i++)
              i1[i] = new JMenuItem (si1);
              jpop.add (i1[i]);
              jpop.addSeparator();
         m2 = new JMenu ("ETF and Card");
         m3 = new JMenu ("Electronic Banking (e-banking) ");
         m4 = new JMenu ("Electronic Presentment & Payment ");
         jpop1.add (m2);
         jpop1.add (m3);
         jpop1.add (m4);
         i2 = new JMenuItem [7];
         for (int i = 0; i < si2.length; i++)
              i2 [i] = new JMenuItem (si2[i]);
              m2.add (i2[i]);
              m2.addSeparator();
         button = new JButton ("Move your mouse here");
         getContentPane().add (button);
         button.addMouseListener (new MouseAdapter ()
              public void mouseEntered(MouseEvent evt)
                   jpop.show (button, 0,25);
         button2 = new JButton ("Move your mouse here");
         getContentPane().add (button2);
         button2.addMouseListener (new MouseAdapter ()
              public void mouseEntered(MouseEvent evt)
                   jpop1.show (button2, 0,25);
         getContentPane().addMouseListener (new MouseAdapter ()
              public void mouseEntered(FocusEvent me)
                   jpop.hide();
                   repaint();

    Any solution ?....
    Thanks.

  • LU Fails to create ABE

    I have the following filesytems on my fully patched Solaris 10 machine:
    /export/home
    /ZONES/reg-otm3
    /ZONES/reg-otm4
    Note that reg-otm3 and reg-otm4 are whole-root zones, up and running.
    The above filesystems are all part of my SAN network. I want to create an ABE on one of my internal disks, but the lucreate barfs when it sees the zones:
    root@reg-otm2 # lucreate -c "San_Disk" -m /:/dev/dsk/c0t1d0s0:ufs -n "Internal_Disk_1"
    Discovering physical storage devices
    Discovering logical storage devices
    Cross referencing storage devices with boot environment configurations
    Determining types of file systems supported
    Validating file system requests
    Preparing logical storage devices
    Preparing physical storage devices
    Configuring physical storage devices
    Configuring logical storage devices
    Analyzing system configuration.
    No name for current boot environment.
    Current boot environment is named <San_Disk>.
    Creating initial configuration for primary boot environment <San_Disk>.
    The device </dev/dsk/c3t50060E8005B00B14d0s0> is not a root device for any boot environment; cannot get BE ID.
    PBE configuration successful: PBE name <San_Disk> PBE Boot Device </dev/dsk/c3t50060E8005B00B14d0s0>.
    Comparing source boot environment <San_Disk> file systems with the file
    system(s) you specified for the new boot environment. Determining which
    file systems should be in the new boot environment.
    Updating boot environment description database on all BEs.
    Searching /dev for possible boot environment filesystem devices
    Updating system configuration files.
    The device </dev/dsk/c0t1d0s0> is not a root device for any boot environment; cannot get BE ID.
    Creating configuration for boot environment <Internal_Disk_1>.
    Source boot environment is <San_Disk>.
    Creating boot environment <Internal_Disk_1>.
    Creating file systems on boot environment <Internal_Disk_1>.
    Creating <ufs> file system for </> in zone <global> on </dev/dsk/c0t1d0s0>.
    Mounting file systems for boot environment <Internal_Disk_1>.
    Calculating required sizes of file systems for boot environment <Internal_Disk_1>.
    Populating file systems on boot environment <Internal_Disk_1>.
    Checking selection integrity.
    Integrity check OK.
    Populating contents of mount point </>.
    Copying.
    Creating shared file system mount points.
    Copying root of zone <reg-otm3> to </.alt.tmp.b-Nwg.mnt/ZONES/reg-otm3-Internal_Disk_1>.
    ERROR: Internal error: /.alt.tmp.b-Nwg.mnt/ZONES/reg-otm3-Internal_Disk_1 is missing
    Copying root of zone <reg-otm4> to </.alt.tmp.b-Nwg.mnt/ZONES/reg-otm4-Internal_Disk_1>.
    ERROR: Internal error: /.alt.tmp.b-Nwg.mnt/ZONES/reg-otm4-Internal_Disk_1 is missing
    Creating compare databases for boot environment <Internal_Disk_1>.
    Creating compare database for file system </>.
    Updating compare databases on boot environment <Internal_Disk_1>.
    Making boot environment <Internal_Disk_1> bootable.
    ERROR: unable to mount zones:
    zoneadm: /.alt.tmp.b-aMg.mnt/ZONES/reg-otm3-Internal_Disk_1: No such file or directory
    could not verify zonepath /.alt.tmp.b-aMg.mnt/ZONES/reg-otm3-Internal_Disk_1 because of the above errors.
    zoneadm: zone reg-otm3 failed to verify
    ERROR: unable to mount zone <reg-otm3> in </.alt.tmp.b-aMg.mnt>
    ERROR: unmounting partially mounted boot environment file systems
    ERROR: cannot mount boot environment by icf file </etc/lu/ICF.2>
    ERROR: Unable to remount ABE <Internal_Disk_1>: cannot make ABE bootable
    ERROR: no boot environment is mounted on root device </dev/dsk/c0t1d0s0>
    Making the ABE <Internal_Disk_1> bootable FAILED.
    ERROR: Unable to make boot environment <Internal_Disk_1> bootable.
    ERROR: Unable to populate file systems on boot environment <Internal_Disk_1>.
    ERROR: Cannot make file systems for boot environment <Internal_Disk_1>.
    I just want to be able to tell lucreate to ignore the zones, but I get the same results when I use the "-x" qualifiers as well.
    Any ideas?
    TIA
    Rick

    1) I would move the creation of the frame to init. I like to create objects only then when they are needed. And when creating the class it is not needed. But it is needed when the applet starts.
    2) You forgot to create a container that can hold objects. Try to create a JPanel where you can add your Buttons to. Then add the JPanel to the ContentPane.
    public class JAppletExample extends JApplet {
        JFrame jfrmTest;
        JPanel jpnlTest;
        public void init() {
            // initializing objects
            jfrmTest = new JFrame("This is a test");
            jpnlTest = new JPanel();
            // setting parameters
            jpnlTest.setBackground(Color.white);
            jpnlTest.setLayout(new FlowLayout());
            jpnlTest.add(new JButton("Button 1"));
            jpnlTest.add(new JButton("Button 2"));
            jpnlTest.add(new JButton("Button 3"));
            // adding JPanel to ContentPane
            jfrmTest.getContentPane().add( jpnlTest );
            // setting size and visibility
            jfrmTest.setSize(400, 150);
            jfrmTest.setVisible(true);
    }Hope this helps, Rommie.

  • How to invoke a method in JApplet from javascript.

    We want to invoke a method in JApplet from javascript.
    with the help Java Plug-in HTML Converter Version 1.3, we have generated OBJECT/EMBED tag for
    the following applet tag.
    <APPLET CODE = "SimpleApplet" WIDTH = 200 HEIGHT = 300 NAME = "simpleApplet"
    MAYSCRIPT = true>
    <PARAM NAME = "p1" VALUE = "v1">
    </APPLET>
    it is given the following code
    <!--"CONVERTED_APPLET"-->
    <!-- CONVERTER VERSION 1.3 -->
    <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = 200 HEIGHT = 300 NAME = "simpleApplet"
    codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
    <PARAM NAME = CODE VALUE = "SimpleApplet" >
    <PARAM NAME = NAME VALUE = "simpleApplet" >
    <PARAM NAME = MAYSCRIPT VALUE = true >
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
    <PARAM NAME="scriptable" VALUE="false">
    <PARAM NAME = "p1" VALUE = "v1">
    <COMMENT>
    <EMBED type="application/x-java-applet;version=1.3" CODE = "SimpleApplet" NAME =
    "simpleApplet" WIDTH = 200 HEIGHT = 300 MAYSCRIPT = true p1 = "v1" scriptable=false
    pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED></COMMENT>
    </NOEMBED></EMBED>
    </OBJECT>
    <!--
    <APPLET CODE = "SimpleApplet" WIDTH = 200 HEIGHT = 300 NAME = "simpleApplet"
    MAYSCRIPT = true>
    <PARAM NAME = "p1" VALUE = "v1">
    </APPLET>
    -->
    <!--"END_CONVERTED_APPLET"-->
    But, even after trying to invoke method in the JApplet from javascript, it is not being invoked in
    Netscape. it is being invoked from
    IE after changing the scriptable = true. Is there any such parameter to change, to invoke the
    method in JApplet from javascript?
    can anybody give any suggestion?

    hi there,,
    well the same problem exists with my code also, NS fails to call the function from java applet... if u get the answer please mail me on [email protected]

  • OnMouseClicked Event Is Failing To Fire

    After clicking on the blue rectangle while the program is running the onMouseClicked Event fails to fire. I am expecting a message to appear in NB's Output window. Below is the relevant source code in relation to handling the onMouseClicked event:
    package javafx_test;
    import javafx.scene.control.Control;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.Node;
    public class ControlTest extends Control{
        def rect = Rectangle{
            fill: Color.BLUE
            height: 20 width: 20
            onMouseClicked: function(me){println("Events are working perfectly!")}
        protected override function create(): Node{
            return rect;
    }Have I missed anything in relation to handling the onMouseClicked event for the blue rectangle?
    Edited by: digi_pixel on Jun 8, 2009 10:54 PM

    I upgraded my custom skinnable control (as shown in [Controls+Skins / CSS - Do Not Scale (BUG)|http://forums.sun.com/thread.jspa?threadID=5363533] in a compact form). I had some trouble, but with a little help from the MediaBox sample, I finally had something working.
    The custom control is useless and ugly, but it does its work in testing the making of custom controls! :-)
    Here is the code:
    StyledControl.fx
    public class StyledControl extends Control
      // Data related to the control (the model)
      package var count: Integer;
      package var content: String;
      public override var focusTraversable = true;
      init
        skin = ControlStyler {}
      package function Incr()
        count++;
        content = "{count}";
    ControlStyler.fx
    public class ControlStyler extends Skin
      //-- Skinable properties
      public var size: Number = 20;
      public var fill: Color = Color.GRAY;
      public var textFill: Color = Color.BLACK;
      public var focusFill: Color = Color.BLUE;
      var shape: Polygon;
      var focusHighlight: Circle;
      init
        shape = Polygon
          points: bind
            0.0, size * 2,
            size, size * 2,
            size / 2, 0.0
          fill: bind fill
        behavior = ControlBehavior { info: bind control.id }
        node = Group
          content:
            shape,
            Text
              x: bind size / 2 - 3
              y: bind size * 2 - 5
              fill: bind textFill
              content: bind (control as StyledControl).content
            Text
              x: 0
              y: bind size * 2 + 10
              content: bind control.id
          //-- Behavior: call controller for actions
          onMouseReleased: function (me: MouseEvent): Void
            (behavior as ControlBehavior).HandleClick(me)
      public function ShowIncrement()
        var df = fill;
        fill = Color.RED;
        Timeline
          keyFrames: [ at(2s) { fill => df tween Interpolator.DISCRETE } ]
        }.play();
      public function ShowFocus()
        focusHighlight = Circle
          centerX: size / 2
          centerY: -5
          radius: 5
          fill: focusFill
        insert focusHighlight into (node as Group).content;
      public function HideFocus()
        delete focusHighlight from (node as Group).content;
      public override function contains(localX: Number, localY: Number): Boolean
    //~     println("contains for {control.id}: {localX} {localY}");
        return shape.contains(localX, localY);
      public override function intersects(localX: Number, localY: Number,
          localWidth: Number, localHeight: Number): Boolean
    //~     println("intersects for {control.id}: {localX} {localY} {localWidth} {localHeight}");
        return shape.intersects(localX, localY, localWidth, localHeight);
      protected override function getPrefWidth(height: Number): Number { size }
        protected override function getPrefHeight(width: Number): Number { size * 2 }
    ControlBehavior.fx
    public class ControlBehavior extends Behavior
      public var info: String; // Only for debug information...
      var control = bind skin.control as StyledControl;
      public override function callActionForEvent(e: KeyEvent)
        println("{info}{control.count}: KeyEvent: {e}");
        if (e.char == '+')
          Incr();
      package function HandleClick(me: MouseEvent): Void
        control.requestFocus();
        // I miss  onFocus() and onBlur() methods?
        (skin as ControlStyler).ShowFocus();
        Incr();
      function Incr(): Void
        control.Incr();
        println("{info}: Ouch! -> {control.count}");
        var sk = skin as ControlStyler;
        sk.ShowIncrement();
    TestStyling.fx
    Stage
      title: "Test Styling Controls"
      scene: Scene
        width:  500
        height: 500
        content:
          StyledControl { id: "Bar", translateX: 50, translateY: 100 }
          StyledControl { /* No id */translateX: 150,  translateY: 100 }
          StyledControl { id: "Foo", translateX: 250, translateY: 75 }
          StyledControl { id: "Gah", translateX: 350, translateY: 100 }
        stylesheets: "{__DIR__}controlStyle.css"
    controlStyle.css
    /* Default style of all styled controls */
    StyledControl
      size: 20;
      fill: #FF8800;
    /* Specify changes per control identified by their ID */
    StyledControl#Foo
      size: 50;
    StyledControl#Bar
      fill: #09FF0F;
      text-fill: green;
      focus-fill: dark-green;
    }I have yet to discover how to handle focus transversal, ie. changing the style of the control when it receives or loose the focus, be it by keys (Tab/Ctrl+Tab when control is focusTransversable) or with mouse (I handle the focus gain but I don't know what if the previously focused control so I cannot remove it).

Maybe you are looking for