JavaFX 2 + Swing + Webstart How do we make it as painless as possible

My team supports a fairly sophisticated swing application and we would love to integrate some FX 2.0 features. Before going too far down that road we’re trying to figure out the best way to minimize the pain for our users.
I see that fx aware jnlp files can have a fall back launch target however, it seems like the fx aware launch target has to be a full blooded FX application. I created a spike with a simple main and a JFrame and it won’t run.
For example:
<jfx:javafx-desc width="100" height="100" main-class="test.MySwingMain" name="Some sample app" />
If MySwingMain doesnt inherit from Application i get an error.
In our current application prototypes when you launch Swing plus FX components in them on a computer which does not have FX installed, the application launches fine. It makes no complaints about FX not being installed. However it throws class not found exceptions when you touch any of the fx stuff. I would like to have webstart realize that they don't have fx and allow them to install it but i have only been able to make the default NoJavaFXFallback stuff trigger when the main is in an FX application.
Is there another way to have my swing application prompt the user to download JavaFX? It may not be possible to allow javascript to do the detection and installation prompt. We would like to handle it at the jnlp/java level but this only seems possible with main classes that inherit from “Application”. Am I missing something?
I even went so far as to create a FX 2.0 boot strap main class which just creates a swing frame but that behaves strangely when you launch it from webstart.

Great question for which, unfortunately, I don't have a good answer.
There is a request for more complete documentation for custom deployments which possibly would have helped you had it existed:
http://javafx-jira.kenai.com/browse/RT-19981 Enhancements to fallback documentation in Deployment Guide
This update to the deployment guide is scheduled for 2.2 (release after next).
Should you have suggestions for missing adjustments to the JavaFX deployment guide, then you can create or comment on documentation jiras or email feedback to:
[email protected]
Also, custom FallBack or JavaFX launchers may become a bit easier to create when the sources for JavaFX deployment code (especially the default launcher and fallback class implementations) are made public (I believe that is planned, but not sure when).

Similar Messages

  • How to customize a javafx.ext.swing.Panel

    Seid gegrüsst
    I want to customize a javafx.ext.Panel for a little testapplication. It's not possible to use something else, because the customized Panel should be in a ScrollPane.
    How ever, in ordinary java I simply override the public void paint(Graphics g) method and place my drawing routine into it.
    Is there a similar way in javafx to customize a Panel?
    carpe noctem
    livevil

    Hi.
    To answer your question: No.
    When you look into the sources of javafx.ext.swing:
    AbstractPanel (the base class for Panel) does not extend JPanel.
    Instead, it has an attribute of type JPanelImpl (basically a javax.swing.JPanel).
    So there is no chance to influence the paint method's behaviour in the Panel class.
    The only possibility would be to extend the original JPanelImpl (overriding its paint method) and to rewrite AbstractPanel and Panel.
    Regards,
    Jens

  • Newbie qs. JavaFx vs Swing?

    I looked through the JavaFx introduction and samples, but wish there could be clarification of the following which other developers too might wonder about:
    Should I write my app in Swing or Java Fx - what considerations should guide my choice?
    It seems that Fx is an alternative or competitor to applets or Google Web toolkit or Flash.
    Can you access the file system, work offline?
    thanks,
    Anil

    Yes you're right in that there are many considerations that involved in choosing between JavaFX or Swing (or some other technology) and for the most part a lot of it is just going to come down to opinions rather than hard and fast rules.
    First of all, JavaFX applications whether they are deployed as Applets, via Web Start, or with a standalone installer can access the file system, work offline, open sockets etc. The restriction is that if deployed as an Applet or via Web Start the application has to be "signed" and the user has to accept the signed application (click "Yes" on a security warning).
    Having said that even unsigned Applets/WebStart applications do have limited access to the file system (a private sandbox) and can open connections back to their originating server. Applets used to be restricted to running in the browser but now they can be dragged out of the browser and "installed" with a shortcut on the users system. The following link provides a good starting point for more information
    [http://java.sun.com/javase/6/docs/technotes/guides/jweb/index.html]
    Always remember that JavaFX sits on top of Java and often leverages tools, products and technologies to achieve tasks.
    In terms of Swing vs JavaFX some of the things you might want to consider are:
    Tolerance towards new technologies. Is you organisation able to take something "cutting-edge" and is prepared to work around problems or limitations. Or are the stakeholders in the project so risk-adverse that a more mainstream approach would be better.
    Willingness to write code. At this stage you will find that Swing has far more components (widgets) available to it, you can somewhat easily reuse Swing components within JavaFX application but you will need to write and maintain extra code to do so. Also there are other gaps in JavaFX where you'll probably need to write extra code like serialization or dealing with medium-complex event handling (action frameworks). More code appears to have more cost but sometimes you also get the benefit of a better fit to your problem.
    But then on the other hand JavaFX is a language dedicated to writing GUIs so you can also argue that even with the current relative immaturity having support within the language for "bind" will result in less code than the the same application written in Swing.
    What's the lifespan of this project for you organisation? A short-term one-off project might justify the use of JavaFX through it being not strategic to your organisation. But then on the other hand a large long-term project might also justify the use of JavaFX because it's easier to absorb specialists filling in the gaps of JavaFX in a larger team and also you might see how JavaFX is going to be important into the future (obviously a value based opinion).
    What level of "graphics" do you want? The Scene graph within JavaFX makes doing "fancy" graphics, video and animation easier than in Swing.
    Hope this helps.
    - Richard.

  • JavaFx Mobile + Swing Problems

    {color:#000000}{color:#ff0000}{color:#003300}The application runs fine when Run As "Desktop(std. execution mode)" & when changed to Run In "Mobile Emulator" gives following Error :-->{color}
    {color}{color}{color:#ff0000}Error preverifying class javafx.ext.swing.JTextFieldImpl
    java/lang/NoClassDefFoundError: com/sun/javafx/scene/BackgroundSupport$BackgroundSupportable
    ERROR: preverify execution failed, exit code: 1
    {color}{color:#000000}{color:#0000ff}C:\Documents and Settings\pravin.patil\My Documents\NetBeansProjects\ColorSlider\nbproject\build-impl.xml:143: exec returned: -1
    {color}{color:#ff0000}BUILD FAILED (total time: 8 seconds){color}
    How to use Swing components in JavaFX Mobile apps??
    Thanks & Regards,
    Pravin{color}
    Edited by: pravinpatil23 on Mar 30, 2009 3:40 AM

    You can provide visual feedback of clicking.
    Here is a primitive (crude!), naive native button, as an example of such effect. I wanted to make it look like it was physically pressed.
    public class NativeButton extends CustomNode
      var arcSize: Number;
      var message: String;
      var width: Number;
      var height: Number;
      var hole: Rectangle;
      public var displacement: Number;
      override protected function create(): Node
        arcSize = height / 5.0;
        displacement = 3;
        hole = Rectangle
          x: 0, y: 0
          width: width
          height: height
          arcWidth: arcSize,  arcHeight: arcSize
          fill: Color.BLACK
        clip = hole;
        Group
          content:
            hole
            Rectangle
              x: 0, y: 0
              width: width
              height: height
              arcWidth: arcSize,  arcHeight: arcSize
              fill: LinearGradient
                startX: 0.0, startY: 0.0, endX: 1.0, endY: 1.0
                proportional: true
                stops:
                  Stop { offset: 0.0, color: Color.LIGHTBLUE }
                  Stop { offset: 1.0, color: Color.BLUE }
              onMousePressed: ShowPressed
              onMouseReleased: ShowReleased
            Rectangle
              x: height / 9.0, y: height / 9.0
              width: width - 2 * height / 9.0
              height: height * 7 / 9.0
              arcWidth: arcSize,  arcHeight: arcSize
              fill: LinearGradient
                startX: 0.0, startY: 0.0, endX: 0.0, endY: 1.0
                proportional: true
                stops:
                  Stop { offset: 0.0, color: Color.LIGHTBLUE }
                  Stop { offset: 1.0, color: Color.BLUE }
            Text
              x: width / 7, y: height / 1.4
              content: message
              fill: Color.YELLOW
              font: Font.font(null, FontWeight.BOLD, 36);
      function ShowPressed(e: MouseEvent): Void
        this.translateX = this.translateY = displacement;
        hole.translateX = hole.translateY = -displacement;
    //~     println("Clicked {this}");
      function ShowReleased(e: MouseEvent): Void
        this.translateX = this.translateY = 0;
        hole.translateX = hole.translateY = 0;
    //~     println("Released");
    function run()
    def BASE_SIZE = 300;
    Stage
      title: "Native JavaFX Button"
      scene: Scene
        width:  BASE_SIZE
        height: BASE_SIZE
        fill:   Color.web('#00BABE')
        content:
          Group
            translateX: 20
            translateY: 20
            content:
              NativeButton { message: "Click Me", width: 200, height: 50 }
    }You can add effects, do something on hovering, etc.

  • 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 do I make a JTable's header sorting actually change the actual table?

    How do I make a JTable's header sorting actually change the actual table?
    Currently, I'm using
    table.setAutoCreateRowSorter(true);to allow the user to sort the table.
    However, I want to be able to load something based on the selected row's index. The problem is that when the table is rearranged, the change appears to only be local, in other words, the actual table isn't changing.
    For instance:
    index 0 "A"
    index 1 "B"
    index 2 "C"
    Sorted in reverse gives me
    "C"
    "B"
    "A"
    But C is still index 2 (instead of 0).
    Thanks in advance.

    Cross posted and answered in the Swing forum.
    [http://forums.sun.com/thread.jspa?threadID=5353865]
    I see this is not your first incidence of cross posting. In future, please post a question once only.
    db

  • 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.

  • How do you make an array of image icons and then call them?

    How do you make an array of image icons and then call them, i have searched all over the internet for making an array of icons, but i have
    found nothing. Below is my attempt at making an array of icons, but i cant seem to make it work. Basically, i want the image to match the value of the roll of the dice (rollVal)
    Any help would be greatly appreciated, some code or link to tuturial, ect.
    /** DiceRoller.java
    * Roll, print, Gui
    import javax.swing.*;
    public class DiceRoller extends JFrame
         private ImageIcon[] image  ;
         public String[] images = { "empty", "dice1.jpg",
                   "dice2.jpg", "dice3.jpg", "dice4.jpg",
                   "dice5.jpg", "dice6.jpg" };
         public Dice die;
         private int rollVal;
         public int rollNum;
         private JLabel j1;
         public DiceRoller(){
              j1= new JLabel("");
           die =new Dice();
           int rollVal;
           rollVal = die.roll();     
           image = new  ImageIcon[images.length];
         for(int i = 0; i < images.length; i++){
          image[i] = new ImageIcon(images);
         if (image!=null){
              j1.setIcon(image[rollVal]);
         System.out.println("Roll = "+die.roll());

    Demo:
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    public class IconExample {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    launch();
        static void launch() {
            try {
                Icon[] icons = new Icon[6];
                for(int i=0; i<icons.length; ++i) {
                    String url = "http://www.eureka-puzzle.be/cast/images/dice" + (i + 1) + ".jpg";
                    icons[i] = new ImageIcon(new URL(url));
                display(icons);
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
        static void display(Icon[] icons) {
            JPanel cp = new JPanel();
            for(Icon icon : icons) {
                cp.add(new JLabel(icon));
            JFrame f = new JFrame();
            f.setContentPane(cp);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • Variable binding with javafx.ext.swing.SwingSlider

    My first javafx program consists of a slider and a text box, the text box displays the current value of the slider. The problem is the text box does not display anything when the program just starts up, but only gets populated once I change the value of the slider. I am not sure what I am doing wrong. Here is the code:
    import javafx.scene.control.*;
    import javafx.scene.*;
    import javafx.stage.*;
    import  javafx.ext.swing.*;
    import javafx.scene.layout.*;
    var BPMSlider = SwingSlider {
        minimum: 10
        maximum: 250
        value: 60
    }; //BPMSlider
    var BPM = bind "{BPMSlider.value}";
    var BPMDisplay = TextBox {
         text: bind BPM
        columns: 3
    }; //BPMDisplay;
    Stage  {
        title: "Slider";
        width: 1000
        height: 500
        visible: true
       // Set the scene
       scene:
           Scene {
           content:       
               HBox{ spacing: 10 content:[ BPMSlider, BPMDisplay ] }
           } // Scene
    }Thanks!

    Hi,
    I don't know how to solve it with binding values, but I managed to solve it with temporary int value which contains Slider.value.
    If any one can help us with solving this binding value we are waiting for answer.
    Here is the code:
    package slider;
    import javafx.ext.swing.*;
    import javafx.scene.*;
    import javafx.scene.control.*;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.*;
    import javafx.stage.*;
    var tempSliderVal:Integer = 60; // temp BPMSlider value
    var BPMSlider = SwingSlider {
        minimum: 10;
        maximum: 250;
        value: bind tempSliderVal with inverse;
        onMouseDragged: function (e:MouseEvent) {
            BPMDisplay.text = tempSliderVal.toString();
        onMouseClicked: function (e:MouseEvent) {
            BPMDisplay.text = tempSliderVal.toString();
    }; //BPMSlider
    var BPMDisplay = TextBox {
         text: tempSliderVal.toString();
        columns: 3;
    }; //BPMDisplay;
    Stage  {
        title: "Slider";
        width: 1000;
        height: 500;
        visible: true;
        // Set the scene
        scene: Scene {
            content: HBox{
                spacing: 10;
                content:[ BPMSlider, BPMDisplay ];
        } // Scene
    }

  • How do I make this program generate a new problem once the button is hit

    Here is the code... appreciate any help given
    How do I make this program generate a new set of problem when the "NEXT" button is clicked and continue until the END button is hit
    package javaapplication3;
    import java.awt.GridLayout;
    import java.awt.Window;
    import javax.swing.*;
    import java.awt.event.*;
    * @author Sylvester Saulabiu
    class Grid extends JFrame{
        final int score = 0;
        final int total = 0;
        Grid(){
            //Set Layout of Flashcard
            setLayout(new GridLayout(4, 4, 2 , 2));
            //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");
            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);
            //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);
            //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
      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();
    String Generator1(){
         int randomnum;
         randomnum = (1 + (int)(Math.random() * 20));
         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 5, 2009 4:39 PM

    Extract code into methods, so that when an action is performed a method is called. That way you can reuse the method for purposes such as resetting textfields to their default values, scores to default values, etc.
    You can go one step further and seperate the GUI layer from the processing layer, by deriving classes that for example maintain and calculate a score.
    Mel

  • How do I make a "Character Select" system?

    I'm making a game for school that is a vertical scrolling shooter (like the Raiden series), based off of the anime Galaxy Angel. For anyone who has seen GA would know there's 5 main characters, all of which I have put in my game. My program is an application (so swing answers only please), and made up of 4 classes: Title Page, Character Select, Main Game, and Credits. I intend to make my program load different Player sprites depending on what character is chosen. Can someone tell me how I can make my Main Game class read which character has been chosen from my Character Select class?

    A very quick and easy way of doing this with Swing is using the JRadioButton class. The following suggestion is similar to a technique used in "How to use Radio Buttons".
    http://java.sun.com/docs/books/tutorial/uiswing/components/button.html#radiobutton
    Inside CharSel class:
    First, declare a class String variable called "userIcon" or something at the top of your program. This will be the path of the icon for your user.
    private static String userIcon=null;When you're setting up the GUI for your CharSel screen, use an array of JRadioButtons for the character buttons. In the for loop where you initialize each button, group them all, and set up the basics (ie: stylize the button to make it feel more like a game), add something like this:
    buttons.addActionListener(this); //assuming you've implemented ActionListener
    buttons[i].setActionCommand("images/charIcon"+i+".gif");
    The i variable is just an int; the current index of your radio button array in your for loop. An action command is simply a String passed to the ActionEvent of your ActionListener.
    You would then add something like the following so you can retrieve the icon's path from other classes:
    public static void setUserIconPath(String s) { this.userIcon = userIcon; }
    public static String getUserIconPath() { return userIcon; }
    //called when a radio button is pressed
    public void actionPerformed(ActionEvent e) {
      //retrieve the action command
      setUserIconPath(e.getActionCommand());
    }When you are writing your actual game classes, you'll create the user image using the static methods:
    ImageIcon portrait = new ImageIcon(CharSel.getUserIconPath());If you wish to avoid the static methods (which may cause problems depending on how you use them), you can set the constructor of your MainGame class to accept the icon's path (or just the ImageIcon itself).
    Alternately, you could simply call a method passing the path/imageicon [i]after you initialize your MainGame class.
    Other techniques may include constant ints and a switch statement (which checks something like CharSel.selectedIcon() == CharSel.BOB). Of course, a more typesafe way of doing that would be to use enums. If you did use enums, you could even include methods for your enum constants (ie: CharSel.Chars.BOB.getImageIcon() may return Bob's ImageIcon).
    Good luck!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How do i make the old frame dissapear when i click a button for a new frame

    I have a program were you have 2 buttons in a frame. When you click on a choice a new frame pops up with another choice. I wanted to know how can i make the old frame dissapear after the user makes the choice and the new frame has come up?
    Thank you,
    Dan

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Frame extends JFrame implements ActionListener
         private JButton Three;
         private JButton Four;
         private JButton One;
         private JButton Two;
         static int num = 0;
    public Frame()
         JPanel p1 = new JPanel();
    getContentPane().add(p1);
         if(num == 0)
         p1.add(One = new JButton("Admin"));
         One.addActionListener     (this );
         p1.add(Two = new JButton("Buy"));
         Two.addActionListener     (this );
    if(num == 1)
         this.dispose();
         p1.add(Three = new JButton("Password"));
         Three.addActionListener (this);
    if(num == 2)
         p1.add(Four = new JButton("Product-ID"));
         Four.addActionListener(this);
    public void actionPerformed(ActionEvent e)
         if (e.getSource() == One)
              num = 1;
              Frame g = new Frame();
              g.pack();
              g.setVisible(true);
    if (e.getSource() == Two )
                   num = 2;
                   Frame h = new Frame();
              h.pack();
              h.setVisible(true);
         if(e.getSource() == Three )
              System.out.println("Password");
         if(e.getSource() == Four)
                   System.out.println("Product-ID");
    public static void main(String[] args)
         Frame frame = new Frame();
    frame.pack();
    frame.setVisible(true);

  • How can i make the installer

    i hava allmost completed my project (Java Swing and Ms Access).
    but i dont know how to make the EXE & installer. in my computer i have dual OS. one have JVM and the other have not JVM. I am using NetBeans 5.5.1 as IDE. When i am trying to run application.jar for Dos Prompt. it is running but when i am trying to it on the other OS it is not running and give an error message something " Don't have the main class..." please help me.
    How can i make a installer of my project with which i can install the package any where.

    you can use install4j utility.. it is open source so u can have a free copy..

  • How do I make a new MouseEvent to my table

    hi,
    i create a new class
    public class exoTabla extends javax.swing.JScrollPane implements TableModelListener {
            public void getDatos() {
                      exodo.sia.libreria.tabla.exoTablaModelo modelo = new exodo.sia.libreria.tabla.exoTablaModelo(_DBconexion, _consulta);
                      modelo.addTableModelListener(this);
                     _tabla = new javax.swing.JTable(modelo);
            this.viewport.removeAll();
            this.viewport.add(_tabla);
    }if inside the code i put next code, print "-- click" in console, that's ok.
    _tabla.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseDoubleClicked(java.awt.event.MouseEvent evt) {
                    System.out.println(" -- click");
            });but, when I use my new class and I add a Listener, this doesn't work, because I add the Listener to class extends of JScrollPane
    and I want link the Listener to table.
    how do I make a new MouseEvent to my class?
    thanks

    Answered in the multi-post: http://forum.java.sun.com/thread.jspa?threadID=5270152

Maybe you are looking for

  • Error while CIF the PPM - PPM has no activities

    Dear Experts,      When i am trying to CIF the PPM from ECC, i am encounter with the following error: The PPM could not be created because no activity could be generated from the master data upon which this is based. The PPM is not transferred.   Ple

  • How do I upgrade my MacBook from 10.5.8 to Mountain Lion???

    I've owned my MacBook since 2008, the software it is running is Mac Os X 10.5.8, iTunes is 10.6.3. I recently received a Nano for Christmas but I need itunes 10.7. When I looked for available updates there were none. When I tried downloading it from

  • ABAP-based web service returns numeric values with leading zeros

    Hi SOA experts, I have created a web service out of an ABAP function module. Beside other values, this service returns a list of document numbers. All of these numeric values are returned by the web service with leading zeros, but we do want these va

  • Create equal columns in Pages

    Hello all, Well once again I find myself turning to the greatest forum on the internet. HELP..... I am trying to create columns in Pages, but when I do, they are not equal (refer to image). Whatever I do just does not work, how do I get them to be th

  • Need a way to tile node's foreground with image pattern

    So, it is a problem. While background of node can be tiled by image, I can't see such ability for foreground. For example, I want to use little image as a brush and fill Rectangle with it. After docs scouting, nothing was found, but maybe someone kno