New help on java swing GUI.....

k, im new to java. Just started learning a month ago. Anyway, I was wondering how one can link gui together using buttons. For example, when i press enter on a registration gui, it'll take me to the confirmation gui. What's the best way to do this? anyone has any idea or can point me to a website with info. Thanks A lots folks.

Well, bascially you would add a Button (e.g. "Next" or "Submit") to your Window/Panel (whatever you prefer). This add has an ActionListener assigned which will open up the next Window/Panel.
Then you define this button to be your default button on that window (check JRootPane.setDefaultButton() for this) so that Enter will fire the button.
Check the Swing online tutorial for an introduction to Swing and how Buttons (and their associated ActionListener) work.
Thomas

Similar Messages

  • Loading large files in Java Swing GUI

    Hello Everyone!
    I am trying to load large files(more then 70 MB of xml text) in a Java Swing GUI. I tried several approaches,
    1)Byte based loading whith a loop similar to
    pane.setText("");
                 InputStream file_reader = new BufferedInputStream(new FileInputStream
                           (file));
                 int BUFFER_SIZE = 4096;
                 byte[] buffer = new byte[BUFFER_SIZE];
                 int bytesRead;
                 String line;
                 while ((bytesRead = file_reader.read(buffer, 0, BUFFER_SIZE)) != -1)
                      line = new String(buffer, 0, bytesRead);
                      pane.append(line);
                 }But this is gives me unacceptable response times for large files and runs out of Java Heap memory.
    2) I read in several places that I could load only small chunks of the file at a time and when the user scrolls upwards or downwards the next/previous chunk is loaded , to achieve this I am guessing extensive manipulation for the ScrollBar in the JScrollPane will be needed or adding an external JScrollBar perhaps? Can anyone provide sample code for that approach? (Putting in mind that I am writting code for an editor so I will be needing to interact via clicks and mouse wheel roatation and keyboard buttons and so on...)
    If anyone can help me, post sample code or point me to useful links that deal with this issue or with writting code for editors in general I would be very grateful.
    Thank you in advance.

    Hi,
    I'm replying to your question from another thread.
    To handle large files I used the new IO libary. I'm trying to remember off the top of my head but the classes involved were the RandomAccessFile, FileChannel and MappedByteBuffer. The MappedByteBuffer was the best way for me to read and write to the file.
    When opening the file I had to scan through the contents of the file using a swing worker thread and progress monitor. Whilst doing this I indexed the file into managable chunks. I also created a cache to further optimise file access.
    In all it worked really well and I was suprised by the performance of the new IO libraries. I remember loading 1GB files and whilst having to wait a few seconds to perform the indexing you wouldn't know that the data for the JList was being retrieved from a file whilst the application was running.
    Good Luck,
    Martin.

  • How to run Java Swing GUI on embedded ARM Linux platform?

    The object is:
    A touch panel, running Java Swing GUI, with a 25 fps 320x320 mono JPEG image animation and other control buttons.
    What I have now:
    A Developing Board with: ARM926 CPU at 266MHz, 128M RAM, 64M ROM, ported with arm-linux and MiniGUI.
    My plan is:
    1. installing a X-window system to the platform, discarding the MiniGUI.
    2. install j2re-1.3.1-RC1-linux-arm.tar.bz2 to the platform.
    3. run my program developed on a PC.
    My concerns are:
    1. Both X and Java is resource consuming, can a 266MHz ARM CPU meet my requirement?
    2. Is the X a must to run Java Swing GUI? If yes, how can I configure it to minimize the footprint, I mean, install only necessary modules.
    3. Can J2RE 1.3.1, the only port for arm linux, support Swing classes?
    4. Are there other options, such as CDC + PP(AGUI?), how to do it?
    Thanks alot!

    3. Can J2RE 1.3.1, the only port for arm linux, support Swing classes?I'm not entirely sure from your post: is this a J2SE port? If so it will support Swing, but probably needs Qt.

  • Help with implementing Swing GUI within jpg image

    Dear Java Experts,
    I have a question, is there a way to implement java swing objects (ie jbutton, jcombobox, etc) within an imageicon. Basically, i am trying to juggle between ways of getting JSwing GUI into a background jpg image. Please help me. I thank you all in advance.

    You've it back to front.
    Create an transparent extension of JPanel that paints an image on it's
    background before running it's super class paint method.
    You'll need to extend this example to stretch, center or tile the image
    but otheriwse it's complete.
    BTW - you have to pass an argument to this example that is the path of
    the image you want on the background of the panel, like:
    java -cp <whatever> MyJavaProject1 images/something.gif
    Enjoy.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class MyJavaProject1
         static class BackgroundPanel
              extends JPanel
              private ImageIcon mIcon;
              public BackgroundPanel(ImageIcon icon) {
                   mIcon= icon;
                   super.setOpaque(false);
              public void setOpaque(boolean flag) { }
              public void paint(Graphics g)
                   g.drawImage(mIcon.getImage(), 0, 0, null);
                   super.paint(g);
         public static void main(String[] argv)
              JFrame frame= new JFrame(argv[0]);
              BackgroundPanel panel= new BackgroundPanel(new ImageIcon(argv[0]));
              panel.setLayout(new GridLayout(0,2,4,4));
              panel.setBorder(new EmptyBorder(4,4,4,4));
              panel.add(new JLabel("Name"));
              panel.add(new JTextField());
              panel.add(new JLabel("Address"));
              panel.add(new JTextField());
              panel.add(new JLabel("Phone"));
              panel.add(new JTextField());
              frame.getContentPane().add(panel, BorderLayout.CENTER);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setResizable(false);
              frame.setVisible(true);
    }

  • Java Swing GUI Button Image

    Hi, I really need help with this one, I have tried many things and looked at many pages for this but to no avail as of yet.
    I have a Swing GUI in which I want to display an image. The way I am displaying it at the moment is as a button icon as I do not need to be able to alter the images. I can also use the button functionality as displaying something when the image is clicked. So I have an array of image paths which are accesed to load an image into the button and a "Next" button to change the image as required.
    My problem is that when I load an image into the button it moves from it's original location. When there is no image displayed the button is where I want it to be, but when I load an image it moves, this cannot happen. Any ideas.
    Also, when I am trying to click thru the array of images, it starts at the 1st image in the array but then skips to the last image in the array. Here is the code for that.
    // Handle events that arise from the "Next" button being clicked
    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {
    if (jComboBox1.getSelectedIndex() == 1)
         for (int i = 1; i < juniorImageIndex.length; i++)
         jButton8.setIcon(new javax.swing.ImageIcon(juniorImageIndex));
    else if (jComboBox1.getSelectedIndex() == 2)
         for (int i = 1; i < seniorImageIndex.length; i++)
         jButton8.setIcon(new javax.swing.ImageIcon(seniorImageIndex[i]));
    juniorImageIndex and seniorImageIndex are obviuosly the arrrays with the file paths for the images. The reason I start at index 1 is that I use the 0 index image as the starting image for each part.
    Any help gratefully appreciated, I really hope someone can help, Thanks.

    // Handle events that arise from the "Next" button
    being clicked
    private void
    jButton5MouseClicked(java.awt.event.MouseEvent evt) {
      myImageIndex =(myImageIndex + 1) % imageArray.size();
      resetButtonImage();
    private void resetButtonImage() {
    if (jComboBox1.getSelectedIndex() == 1)
    {//take this out
    //> for (int i = 1; i < juniorImageIndex.length; i++)
    //> {
    jButton8.setIcon(new//> javax.swing.ImageIcon(array[myImageIndex]));
    //> }
    else if (jComboBox1.getSelectedIndex() == 2)
    {//this too
    //> for (int i = 1; i < seniorImageIndex.length; i++)
    //> {
    jButton8.setIcon(new
    javax.swing.ImageIcon(array2[myImageIndex]));//> }

  • Help with java swing

    Hi people!i need some help
    Im a new user for java programming language.Well im programming an application using java swing libraries. I have some problems trying to accesing variables from those swing Jpanels. Ill make it clear....
    Im using Netbeans...
    I have a class for the window (a JFrame) including 2 Jtextfields and 2 Jlabels
    import .......
    public class myclass extends javax.swing.JFrame{
    public double gp;
    public double gv;
    public G() {
    initComponents();
    gpnom=this.gpnom;
    gvnom=this.gvnom;
    private void TXFgpnom(java.awt.event.ActionEvent evt) {        //TXField                                
    gpnom= Double.parseDouble(TXFgpnom.getText());
    gvnom= Double.parseDouble(TXFgvnom.getText());
    .......//theres a lot of more code .for listeners..next...
    Now ive created a new file (a new class)in the same package ,but i cant access public variables from swing class
    //the next class was created in a new file
    public class hi () {
    JPanel prin =(JPanel) new myclass().getContentPane(); //ok
    double number=gpnom // error variable not found
    When i try to get the value of "number" ...i always get "ERROR" And the class for that textfield was public..i think...
    HOw can i use variables from that Jpanel?
    Id appreciate an answer...
    thanx for your help!
    Paco

    In future Swing related questions should be posted in the Swing forum and camickr will be more likely to answer if you have used code tags to properly format your code.
    Luckily this problem does not seem to be Swing related in the least because the public variables you have in your other class are named gp and gv and further when you access public variables (or properties) of a class you must access them by an instance of that class. Which you don't appear to be doing either.

  • Skins in java swing/gui

    hi!!! i just wanna ask you guys and gals if there is a way for Java GUI to implement a skin, you know, those what we can see in Winamp. That's all. Thanks a lot!!! Have a nice day!!! :-)

    //first make sure you define the image in the class, then override the method
    //defining image
    ImageIcon imageIcon = new ImageIcon("images/background.jpg");
    Image image = imageIcon.getImage();
    //overriding the method that paints the background of the JPanel
    public void paintComponent(Graphics g) {
    super.paintComponent(g); //paint background
    if (image != null) { //there is a picture: draw it
    int height = this.getSize().height;
    int width = this.getSize().width;
    g.drawImage(image,0,0, width, height, this);
    //g.drawImage(image, 0, 0, this); //original image size
    } //end if
    } //end paint

  • Help regarding Java Swing

    Hi All,
    I am a bit confused witht the shortcut syntax for adding action listeners for event handling.
    In the Java tutorial it is mentioned that for implementing an event handler following are the three steps:
    1. Create a class that implements ActionListener interface.
    For example:
    public class MyClass implements ActionListener {
    2. Registers an instance of the event handler class as a listener on one or more components.
    For example:
    someComponent.addActionListener(instanceOfMyClass);
    3. In the event handler class, a few lines of code implement the methods in the listener interface.
    For example:
    public void actionPerformed(ActionEvent e) {
    ...//code that reacts to the action...
    In the tutorial a shortcut syntax is also given:
    For Example:
    Class TestApp {
    JButton btn = new JButton("Test");
    btn.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    ...//code that reacts to the action...
    My doubt is:
    1. How are we allowed to create an instance of ActionListener which is an "interface". (doesnt addActionListener expect instance of a class that implements the ActionListener interface? )
    2. How are we able to access local variables of class "TestApp" the inside the actionPerformed() function.
    Could anyone explain more about this shortcut syntax of adding action listeners?
    Thanks in regards
    Arun

    The example uses so-called "anonymous inner classes". ActionListener is an interface, of course. But if you use the construct
    new ActionListener() {
       public void actionPerformed(ActionEvent e) {
       ...//code that reacts to the action...
    }this is about equivalent to defining an inner class
    private class MyActionListener implements ActionListener {
       public void actionPerformed(ActionEvent e) {
       ...//code that reacts to the action...
    }and using that class. The difference is mainly, that the in nthe shortcut notation the class has no explicit name, it is anonymous.
    There are advantages and disadvantages to that. The main disadvantage is, that you create a large amount of classes in this way. I've read somewhere, that SUN is planning to rewrite the examples without the use of anonymous inner classes.

  • Using extends in Java SWING GUI

    i have designed this login page and this other page for checking marks.
    The idea is, if the person who logs on is the particular unique user, he will be able to check the marks of that subject, If other person who logs on and try to check the mark, he will be given a message instead.
    So in order to retrieve the person's username n check to see if he can be authorized, i have to retrieve the textfield results from the login page and then implemented it into my method in the mark's page. so i just extends the Login page.
    I did the dispose method n everything, and now
    a) when i logged on as that user, my marks page dioesn't come out as planned, instead a login page comes out
    b) when i run the marks page , the login page and my mark's page come out at the same time ?
    why is this so ?

    The reason your login page is showing up on your next panel is because you extend it. When you extend a class you inherit everything about that class including the gui. You should just make 2 seperate classes and pass in the values you want either through the constructor or make some methods to pass in the value. So what you should do is make your login class take the username and password then validate it. If the user has entered a valid username/password then pass the next class the username.Here is some suedo code I'm not going to write out everything because it would take too long.class Login extends JDialog
       private String userName;
       private String passWord;
       public Login()
           // add your textfields and other gui components
          // take in the username and password
          // verify them in some other method
          if(this.validateUser() == true)
              MarksPanel markPanel = new MarksPanel(username);
       public boolean validateUser()
            // some code to check username and password
    class MarksPanel extends JPanel
       public MarksPanel(String Username)
           // now you have the username in a seprate class and
           // since you don't extend Login here you won't see the same
          // Login panel on top of this

  • Java Swing Help

    Hi, I am currently using a program called JPadPro for my java source codes. I am just beginning to learn java and I have just started on Java Swing GUI codings. My problem is that the program compiles, but it doesn't run. It always give me an error saying
    "Cannot find main method, Program will exit". there is nothing wrong with my source code because I can run somewhere else. I think I didn't configure my Jpadpro correctly. (but anything without GUI does work)
    Thank You for your help :)

    Even though you are running a swing application, you still need a main method just as in non-GUI applications. The main should create an instance of the JFrame at the base of you swing app. A simple example is as follows:
    public class mySwingApp extends JFrame {
    public mySwingApp(String title) {
    super(title);
    // GUI components, layouts, possible listeners here
    public static void main(String[] args) {
    JFrame mainFrame = new mySwingApp("My first swing app");
    mainFrame.setSize(200, 200);
    mainFrame.setVisible(true);
    }Hope this helps some!
    -JBoeing

  • Launching Swing GUI from Oracle Forms Web Based

    Hi there,
    I have oracle forms which call a shell script which initiates the java swing gui. I am using host command to run this script. When I am doing it on unix server everything works fine. Now we want same application on web now i am getting problem. The host command is not working in this case. It can not launch the java gui. Can anybody tell me what will be the nice approach to do it.
    Thanks
    Ranjan

    Hi,
    you'll have to create a Java Bean in Forms that calls the runtime. You can also use webutil, available on otn to call a client side host command.
    Frank

  • Chess: java swing help need

    Hi, I have just learn java swing and now creating a chess game. I have sucessfully create a board and able to display chess pieces on the board. By using JLayeredPane, I am able to use drag and drop for the piece. However, there is a problem which is that I can drop the chess piece off the board and the piece would disappear. I have try to solve this problem by trying to find the location that the chess piece is on, store it somewhere and check if the chess piece have been drop off bound. However, I could not manage to solve it. Also, I am very confuse with all these layer thing.
    Any suggestion would be very helpful. Thanks in advance
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class ChessBoard extends JFrame implements MouseListener, MouseMotionListener
    Object currentPosition;
    Color currentColor;
    Dimension boardSize = new Dimension(600, 600);
    JLayeredPane layeredPane;
    JPanel board;
    JPanel box;
    JLabel chessPiece;
    int xAdjustment;
    int yAdjustment;
    public ChessBoard()
    // Use a Layered Pane for this this application
    layeredPane = new JLayeredPane();
    getContentPane().add(layeredPane);
    layeredPane.setPreferredSize( boardSize );
         layeredPane.addMouseListener( this );
    layeredPane.addMouseMotionListener( this );
    // Add a chess board to the Layered Pane
    board = new JPanel();
         // set "board" to the lowest layer (default_layer)
    layeredPane.add(board, JLayeredPane.DEFAULT_LAYER);
    board.setLayout( new GridLayout(8, 8) );
    board.setPreferredSize( boardSize );
    board.setBounds(0, 0, boardSize.width, boardSize.height);
         addShade();
         addPiece();
    public void addShade()
         for (int i = 0; i < 64; i++)
    box = new JPanel( new BorderLayout() );
    board.add( box, BorderLayout.CENTER );
         if( ((i / 8) % 2) == 0)
                   if( (i % 2) ==0)
                        box.setBackground(Color.lightGray);
                   } else {
                        box.setBackground( Color.white);
              } else {
                   if( (i % 2) ==0)
                        box.setBackground(Color.white);
                   } else {
                        box.setBackground(Color.lightGray);
    //Method for adding chess pieces to the board
    public void addPiece()
    // Add a few pieces to the board
         //black pieces
         for (int i = 0; i < 64; i++)
              //adding black pieces
              if (i < 8)
                   String fileName = i + ".gif";
                   JLabel blackPieces = new JLabel( new ImageIcon( fileName ) );
                   JPanel panel = (JPanel)board.getComponent( i );
                   panel.add( blackPieces );
              //adding black pones
              if ((i > 7) && (i < 16))
                   String fileName = "8.gif";
                   JLabel blackPones = new JLabel( new ImageIcon( fileName ) );
                   JPanel panel = (JPanel)board.getComponent( i );
                   panel.add( blackPones );
              //jump to white position (Component 48)
              if (i == 16) i = 48;
              //adding white pones
              if(( i > 47 ) && (i < 56))
                   JLabel whitePones = new JLabel( new ImageIcon("48.gif") );
                   JPanel panel = (JPanel)board.getComponent( i );
                   panel.add( whitePones );
              //adding white pieces
              if (i > 55)
                   String fileName = i + ".gif";
                   JLabel whitePieces = new JLabel( new ImageIcon( fileName ) );
                   JPanel panel = (JPanel)board.getComponent( i);
                   panel.add( whitePieces );
    ** Add the selected chess piece to the dragging layer so it can be moved
    public void mousePressed(MouseEvent e)
    chessPiece = null;
    Component c = board.findComponentAt(e.getX(), e.getY());
         c.setBackground(Color.red);
    if (c instanceof JPanel) return;
    Point parentLocation = c.getParent().getLocation();
    xAdjustment = parentLocation.x - e.getX();
    yAdjustment = parentLocation.y - e.getY();
    chessPiece = (JLabel)c;
    chessPiece.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
    chessPiece.setSize(chessPiece.getWidth(), chessPiece.getHeight());
    layeredPane.add(chessPiece, JLayeredPane.DRAG_LAYER);
    ** Move the chess piece around
    public void mouseDragged(MouseEvent me)
    if (chessPiece == null) return;
    chessPiece.setLocation(me.getX() + xAdjustment, me.getY() + yAdjustment);
    ** Drop the chess piece back onto the chess board
    public void mouseReleased(MouseEvent e)
         Component c = board.findComponentAt(e.getX(), e.getY());
         int x = (int)c.getBounds().getX();
         int y = (int)c.getBounds().getY();
         System.out.println(c.getLocation());
         System.out.println(x + " "+ y);
         c.setBackground(currentColor);
    if (chessPiece == null) return;
    chessPiece.setVisible(false);
    if (c instanceof JLabel)
    Container parent = c.getParent();
         //remove the piece that is capture
    parent.remove(0);
    parent.add( chessPiece );
    else
    Container parent = (Container)c;
    parent.add( chessPiece );
    chessPiece.setVisible(true);
    public void mouseClicked(MouseEvent e) {}
    public void mouseMoved(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    private static void createAndShowGUI()
         //Make sure we have nice window decorations
         JFrame.setDefaultLookAndFeelDecorated(true);
         JFrame frame = new ChessBoard();
         frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
         //Display the window
         frame.pack();
         frame.setResizable( false );
         frame.setLocationRelativeTo( null );
         frame.setVisible(true);
    public static void main(String[] args)
         //Schedule a job for the event-dispatching thread:
         //creating and showing this application's GUI
         javax.swing.SwingUtilities.invokeLater( new Runnable()
                   public void run()
                        createAndShowGUI();
    }

    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class ChessBoardRx extends JFrame implements MouseListener, MouseMotionListener
        Object currentPosition;
        Color currentColor;
        Dimension boardSize = new Dimension(600, 600);
        JLayeredPane layeredPane;
        JPanel board;
        JPanel box;
        JLabel chessPiece;
        int xAdjustment;
        int yAdjustment;
        Container lastParent;
        public ChessBoardRx()
            // Use a Layered Pane for this this application
            layeredPane = new JLayeredPane();
            getContentPane().add(layeredPane);
            layeredPane.setPreferredSize( boardSize );
            layeredPane.addMouseListener( this );
            layeredPane.addMouseMotionListener( this );
            // Add a chess board to the Layered Pane
            board = new JPanel();
            // set "board" to the lowest layer (default_layer)
            layeredPane.add(board, JLayeredPane.DEFAULT_LAYER);
            board.setLayout( new GridLayout(8, 8) );
            board.setPreferredSize( boardSize );
            board.setBounds(0, 0, boardSize.width, boardSize.height);
            addShade();
            addPiece();
    //        populateBoard();
        public void addShade()
            for (int i = 0; i < 64; i++)
                box = new JPanel( new BorderLayout() );
                board.add( box, BorderLayout.CENTER );
                if( ((i / 8) % 2) == 0)
                    if( (i % 2) ==0)
                        box.setBackground(Color.lightGray);
                    } else {
                        box.setBackground( Color.white);
                } else {
                    if( (i % 2) ==0)
                        box.setBackground(Color.white);
                    } else {
                        box.setBackground(Color.lightGray);
        //Method for adding chess pieces to the board
        public void addPiece()
            // Add a few pieces to the board
            //black pieces
            for (int i = 0; i < 64; i++)
                //adding black pieces
                if (i < 8)
                    String fileName = i + ".gif";
                    JLabel blackPieces = new JLabel( new ImageIcon( fileName ) );
                    JPanel panel = (JPanel)board.getComponent( i );
                    panel.add( blackPieces );
                //adding black pones
                if ((i > 7) && (i < 16))
                    String fileName = "8.gif";
                    JLabel blackPones = new JLabel( new ImageIcon( fileName ) );
                    JPanel panel = (JPanel)board.getComponent( i );
                    panel.add( blackPones );
                //jump to white position (Component 48)
                if (i == 16) i = 48;
                //adding white pones
                if(( i > 47 ) && (i < 56))
                    JLabel whitePones = new JLabel( new ImageIcon("48.gif") );
                    JPanel panel = (JPanel)board.getComponent( i );
                    panel.add( whitePones );
                //adding white pieces
                if (i > 55)
                    String fileName = i + ".gif";
                    JLabel whitePieces = new JLabel( new ImageIcon( fileName ) );
                    JPanel panel = (JPanel)board.getComponent( i);
                    panel.add( whitePieces );
        private void populateBoard() {
            int[][] pos = {
                { 9, 7, 5, 1, 3, 5, 7, 9 },
                { 8, 6, 4, 0, 2, 4, 6, 8 }
            for(int j = 0; j < 8; j++) {
                String fileName = "chessImages/" + pos[0][j] + ".jpg";
                JLabel label = new JLabel( new ImageIcon( fileName ) );
                JPanel panel = (JPanel)board.getComponent( j );
                panel.add( label );
            for(int j = 8; j < 16; j++) {
                String fileName = "chessImages/" + 11 + ".jpg";
                JLabel label = new JLabel( new ImageIcon( fileName ) );
                JPanel panel = (JPanel)board.getComponent( j );
                panel.add( label );
            for(int j = 56, k = 0; j < 64; j++, k++) {
                String fileName = "chessImages/" + pos[1][k] + ".jpg";
                JLabel label = new JLabel( new ImageIcon( fileName ) );
                JPanel panel = (JPanel)board.getComponent( j );
                panel.add( label );
            for(int j = 48; j < 56; j++) {
                String fileName = "chessImages/" + 10 + ".jpg";
                JLabel label = new JLabel( new ImageIcon( fileName ) );
                JPanel panel = (JPanel)board.getComponent( j );
                panel.add( label );
         ** Add the selected chess piece to the dragging layer so it can be moved
        public void mousePressed(MouseEvent e)
            chessPiece = null;
            Component c = board.findComponentAt(e.getX(), e.getY());
            c.setBackground(Color.red);
            if (c instanceof JPanel) return;
            lastParent = c.getParent();
            Point parentLocation = c.getParent().getLocation();
            xAdjustment = parentLocation.x - e.getX();
            yAdjustment = parentLocation.y - e.getY();
            chessPiece = (JLabel)c;
            chessPiece.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
            chessPiece.setSize(chessPiece.getWidth(), chessPiece.getHeight());
            layeredPane.add(chessPiece, JLayeredPane.DRAG_LAYER);
         ** Move the chess piece around
        public void mouseDragged(MouseEvent me)
            if (chessPiece == null) return;
            chessPiece.setLocation(me.getX() + xAdjustment, me.getY() + yAdjustment);
         ** Drop the chess piece back onto the chess board
        public void mouseReleased(MouseEvent e)
            Component c = board.findComponentAt(e.getX(), e.getY());
            if(c == null) {
                layeredPane.remove(chessPiece);
                lastParent.add(chessPiece);
                Rectangle r = lastParent.getBounds();
                chessPiece.setLocation(r.x+xAdjustment, r.y+yAdjustment);
                lastParent.validate();
                lastParent.repaint();
                return;
            int x = (int)c.getBounds().getX();
            int y = (int)c.getBounds().getY();
            System.out.println(c.getLocation());
            System.out.println(x + " "+ y);
            c.setBackground(currentColor);
            if (chessPiece == null) return;
            chessPiece.setVisible(false);
            if (c instanceof JLabel)
                Container parent = c.getParent();
                //remove the piece that is capture
                parent.remove(0);
                parent.add( chessPiece );
            else
                Container parent = (Container)c;
                parent.add( chessPiece );
            chessPiece.setVisible(true);
        public void mouseClicked(MouseEvent e) {}
        public void mouseMoved(MouseEvent e) {}
        public void mouseEntered(MouseEvent e) {}
        public void mouseExited(MouseEvent e) {}
        private static void createAndShowGUI()
            //Make sure we have nice window decorations
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame frame = new ChessBoardRx();
            frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
            //Display the window
            frame.pack();
            frame.setResizable( false );
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
        public static void main(String[] args)
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI
            javax.swing.SwingUtilities.invokeLater( new Runnable()
                public void run()
                    createAndShowGUI();
    }

  • Java using GUI's mixed with opengl... needs help...urgent....

    guys, i need help.... is anyone there have an idea about opengl...? ill attach 4 files that needs to be enhanced or debug for possible errors. to see the canvas... you should have atleast all the needed lib and jar of opengl in your pc.
    its urgent, its for our thesis actually....ill be dividing the codes with the use of (" **** ")sign...
    * Main.java
    * Created on 29 January 2007, 08:12
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package longgong;
    * @author welcome
    public class Main {
        /** Creates a new instance of Main */
        public Main() {
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            frmMain f = new frmMain();
    * frmMain.java
    * Created on November 10, 2006, 10:52 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package longgong; // create a floder named longgong and add the class inside
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    * @author all user
    public class frmMain extends JFrame implements ActionListener, ChangeListener, ItemListener{
        JPanel pnlWest, pnlEast, pnlCenter, pnlSouth, pnlTitle, pnlSlider, pnlPlayers;
        JSlider slrSpeed;
        JList lstResults;
        String varResults [] = new String[31];
        JLabel lblPlayers, lblTitle;
        JCheckBox lblPlayer1, lblPlayer2, lblPlayer3, lblPlayer4, lblPlayer5, lblPlayer6;
        ImageIcon imgDice1;
        MyCanvas canvas;
        JButton btnStart, btnStop;
        JMenuBar menuBar;
        JMenu menuFile, menuView, menuHelp;
        JMenuItem menuNew, menuExit, menuIn, menuOut, menuHigh, menuPlay, menuAbout;
        boolean isNew = false;
        /** Creates a new instance of frmMain */
        public frmMain() {
            setLayout(new BorderLayout());
            setTitle("Longgong");
            setSize(780,600);
            canvas = new MyCanvas(getSize().width, getSize().height);
            imgDice1 = new ImageIcon("c:\\java\\images\\one.png");
            menuBar = new JMenuBar();
            menuFile = new JMenu("File");
            menuView = new JMenu("View");
            menuHelp = new JMenu("Help");
            menuNew = new JMenuItem ("New Game");
            menuNew.addActionListener(this);
            menuExit = new JMenuItem ("Exit");
            menuExit.addActionListener(this);
            menuIn = new JMenuItem ("Zoom In");
            menuIn.addActionListener(this);
            menuOut = new JMenuItem ("Zoom Out");
            menuOut.addActionListener(this);
            menuHigh = new JMenuItem ("High Score");
            menuPlay = new JMenuItem ("How To Play");
            menuPlay.addActionListener(this);
            menuAbout = new JMenuItem ("About");
            menuAbout.addActionListener(this);
            menuFile.add(menuNew);
            menuFile.add(menuExit);
            menuView.add(menuIn);
            menuView.add(menuOut);
            menuView.add(menuHigh);
            menuHelp.add(menuPlay);
            menuHelp.add(menuAbout);
            menuBar.add(menuFile);
            menuBar.add(menuView);
            menuBar.add(menuHelp);
            setJMenuBar(menuBar);
            varResults[0] = "Dice Results";
            varResults[1] = "1. 3-4-2";
            varResults[2] = "2. 3-1-4";
            varResults[3] = "3. 3-6-5";
            slrSpeed = new JSlider(0, 100, 0);
            slrSpeed.setPaintTicks(true);
            slrSpeed.setMinorTickSpacing(1);
            slrSpeed.setPaintLabels(true);
            slrSpeed.setSnapToTicks(true);
            slrSpeed.addChangeListener(this);
            slrSpeed.setEnabled(false);
            btnStart =  new JButton("Start");
            btnStart.addActionListener(this);
            btnStop =  new JButton("Stop");
            btnStop.addActionListener(this);
            pnlWest = new JPanel();
            pnlEast = new JPanel();
            pnlCenter = new JPanel();
            pnlSouth = new JPanel();
            pnlTitle = new JPanel();
            pnlSlider = new JPanel();       
            pnlPlayers = new JPanel();
            pnlWest.setLayout(new BorderLayout());
            pnlEast.setLayout(new BorderLayout());
            pnlEast.setPreferredSize(new Dimension(100,400));
            pnlCenter.setLayout(new BorderLayout());
            pnlSouth.setLayout(new FlowLayout());
            pnlTitle.setLayout(new FlowLayout());
            pnlSlider.setLayout(new FlowLayout());       
            pnlPlayers.setLayout(new BoxLayout(pnlPlayers,BoxLayout.Y_AXIS));
            pnlPlayers.setPreferredSize(new Dimension(150,400));
            lblPlayers = new JLabel("  Players: Choice (s)");
            lblPlayer1 = new JCheckBox("None");
            lblPlayer1.addItemListener(this);
            lblPlayer2 = new JCheckBox("None");
            lblPlayer2.addItemListener(this);
            lblPlayer3 = new JCheckBox("None");
            lblPlayer3.addItemListener(this);
            lblPlayer4 = new JCheckBox("None");
            lblPlayer4.addItemListener(this);
            lblPlayer5 = new JCheckBox("None");
            lblPlayer5.addItemListener(this);
            lblPlayer6 = new JCheckBox("None");
            lblPlayer6.addItemListener(this);
            lstResults = new JList(varResults);
            pnlPlayers.add(lblPlayers);
            pnlPlayers.add(lblPlayer1);
            pnlPlayers.add(lblPlayer2);
            pnlPlayers.add(lblPlayer3);
            pnlPlayers.add(lblPlayer4);
            pnlPlayers.add(lblPlayer5);
            pnlPlayers.add(lblPlayer6);
            pnlSlider.add(slrSpeed);
            pnlSlider.add(btnStart);
            pnlSlider.add(btnStop);
            pnlEast.add(BorderLayout.CENTER, lstResults);
            pnlCenter.add(BorderLayout.SOUTH, pnlSlider);    
            pnlCenter.add(BorderLayout.CENTER, canvas);    
            lblTitle = new JLabel("LONGGONG DICE GAME SIMULATION");
            pnlTitle.add(lblTitle);
            getContentPane().add(BorderLayout.NORTH,pnlTitle);   
            getContentPane().add(BorderLayout.WEST,pnlPlayers);
            getContentPane().add(BorderLayout.EAST,pnlEast);
            getContentPane().add(BorderLayout.CENTER, pnlCenter);
            getContentPane().add(BorderLayout.SOUTH,pnlSouth);
            setResizable(false);
            canvas.start();
            show();       
        //name change when player is selected
        public void itemStateChanged(ItemEvent e) {
        Object source = e.getItemSelectable();
        int choice;
        if (source == lblPlayer1) {
            if (lblPlayer1.isSelected()) {
                frmChoices fchoices = new frmChoices(lblPlayer1);
        if (source == lblPlayer2) {
            if (lblPlayer2.isSelected()) {
                frmChoices fchoices = new frmChoices(lblPlayer2);
        if (source == lblPlayer3) {
            if (lblPlayer3.isSelected()) {
                frmChoices fchoices = new frmChoices(lblPlayer3);
        if (source == lblPlayer4) {
            if (lblPlayer4.isSelected()) {
                frmChoices fchoices = new frmChoices(lblPlayer4);
        if (source == lblPlayer5) {
            if (lblPlayer5.isSelected()) {
                frmChoices fchoices = new frmChoices(lblPlayer5);
        if (source == lblPlayer6) {
            if (lblPlayer6.isSelected()) {
                frmChoices fchoices = new frmChoices(lblPlayer6);
           // if (e.getStateChange() == ItemEvent.DESELECTED)
            //...make a note of it...
        //slider speed change
        public void stateChanged(ChangeEvent e){      
               canvas.speed(slrSpeed.getValue());
        public void actionPerformed (ActionEvent e){
            if (e.getActionCommand().equals ("Exit")){
                System.exit (0);     
            //connects to frmNew
            if (e.getActionCommand().equals ("New Game")){
                frmNew n = new frmNew(this);   
                lblPlayer1.setText("None");
                lblPlayer2.setText("None");
                lblPlayer3.setText("None");
                lblPlayer4.setText("None");
                lblPlayer5.setText("None");
                lblPlayer6.setText("None");
                isNew = true;
                lblPlayer1.setSelected(false);
                lblPlayer2.setSelected(false);
                lblPlayer3.setSelected(false);
                lblPlayer4.setSelected(false);
                lblPlayer5.setSelected(false);
                lblPlayer6.setSelected(false);
            if (e.getActionCommand().equals ("Start")){
               slrSpeed.setEnabled(true);
               canvas.setRandomDicePosition();
            if (e.getActionCommand().equals ("Stop")){
                slrSpeed.setValue(0);
                slrSpeed.setEnabled(false);
            //ADDED
             if (e.getActionCommand().equals ("New Game")){
               frmNew n = new frmNew(this);           
            if (e.getActionCommand().equals ("Zoom In")){
                canvas.zoomIn();          
            if (e.getActionCommand().equals ("Zoom Out")){
                canvas.zoomOut();          
            if (e.getActionCommand().equals ("How To Play")){
                frmPlay p = new frmPlay();           
            if (e.getActionCommand().equals ("About")){
                frmAbout a = new frmAbout();           
    package longgong;
    // Java  classes
       import java.awt.*;
       import java.awt.event.*;
       import java.net.URL;
    // GL4Java classes
       import gl4java.GLContext;
       import gl4java.awt.GLAnimCanvas;
       import gl4java.utils.textures.*;
       class MyCanvas extends GLAnimCanvas implements KeyListener, MouseListener
         // holds information on which keys are held down.
          boolean[] keys=new boolean[256];
          float     xrot;                    // X Rotation ( NEW )
          float     yrot;                    // Y Rotation ( NEW )
          float     zrot;                    // Z Rotation ( NEW )
          float[] diceRotX = new float[3];
          float[] diceRotY = new float[3];
          float[] diceRotZ = new float[3];
          float[] diceTranX = new float[3];
          float[] diceTranY = new float[3];
          float[] diceTranZ = new float[3];     
          float speedValue;
          Dice[] D;
          float zoom = -15.0f;
          public MyCanvas(int w, int h)
             super(w, h);
             //Registers this canvas to process keyboard events, and Mouse events
             addKeyListener(this);
             addMouseListener(this);  
             setAnimateFps(60); // seemed to be essential in getting any performance
             speedValue=0.0f;
             diceTranX[0] = -2.0f;
             diceTranY[0] = 2.0f;
             diceTranZ[0] = zoom;
             diceTranX[1] = 2.0f;
             diceTranY[1] = 1.0f;
             diceTranZ[1] = zoom;
             diceTranX[2] = 0.0f;
             diceTranY[2] = -2.0f;
             diceTranZ[2] = zoom;
          public void zoomIn(){
              zoom=zoom+1.0f;
           public void zoomOut(){
              zoom=zoom-1.0f;
          public void speed(float s){
            speedValue=s/100;
        /** void reshape(int width, int height) Called after the first paint command.  */  
          public void reshape(int width, int height)
             if(height==0)height=1;
             gl.glViewport(0, 0, width, height);                       // Reset The Current Viewport And Perspective Transformation
             gl.glMatrixMode(GL_PROJECTION);                           // Select The Projection Matrix
             gl.glLoadIdentity();                                      // Reset The Projection Matrix
             glu.gluPerspective(45.0f, width / height, 0.1f, 100.0f);  // Calculate The Aspect Ratio Of The Window
             gl.glMatrixMode(GL_MODELVIEW);                            // Select The Modelview Matrix
             gl.glLoadIdentity();                                      // Reset The ModalView Matrix     
       /** void preInit() Called just BEFORE the GL-Context is created. */  
          public void preInit()
          { doubleBuffer = true; stereoView = false; // buffering but not stereoview
          public void setRandomDicePosition(){
             for (int i=0; i<3; i++){
               D.setCoordinates(diceRotX[i],diceRotY[i],diceRotZ[i],diceTranX[i],diceTranY[i],diceTranZ[i]);
    D[i].getRandomDice();
    /** void init() Called just AFTER the GL-Context is created. */
    public void init()
    //float width = (float)getSize().width;
    //float height = (float)getSize().height;
    D = new Dice[5];
    D[0] = new Dice(this);
    D[1] = new Dice(this);
    D[2] = new Dice(this);
    //initialize dice location
    for (int i=0; i<3; i++){
    D[i].setCoordinates(diceRotX[i],diceRotY[i],diceRotZ[i],diceTranX[i],diceTranY[i],diceTranZ[i]);
    D[i].getRandomDice();
    gl.glEnable(GL_TEXTURE_2D);                              //Enable Texture Mapping ( NEW )
    gl.glShadeModel(GL_SMOOTH); //Enables Smooth Color Shading
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //This Will Clear The Background Color To Black
    gl.glClearDepth(1.0); //Enables Clearing Of The Depth Buffer
    gl.glEnable(GL_DEPTH_TEST); //Enables Depth Testing
    gl.glDepthFunc(GL_LEQUAL); //The Type Of Depth Test To Do
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Really Nice Perspective Calculations
    public void DrawBoundaries(){
    double x,y;
    double radius = 5.0f;
    gl.glLoadIdentity();                                             // Reset The View
    gl.glTranslatef(0.0f,0.0f,zoom-1.0f);
    gl.glRotatef(90.0f,0.0f,0.0f,1.0f);
    gl.glColor3f(0.6f,0.3f,0.3f);
    gl.glBegin(gl.GL_POLYGON);
    // angle is
    // x = radius * (cosine of angle)
    // y = radius * (sine of angle)
    for (double a=0; a<360; a++) {
    x = radius * (Math.cos(a));
    y = radius * (Math.sin(a));
    gl.glVertex3d(x, y, 0.0f);
    gl.glEnd();
    gl.glColor3f(1.0f,1.0f,1.0f);
    public void DrawGLScene()
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear The Screen And The Depth Buffer
    DrawBoundaries();
    for (int i=0; i<3; i++){
    D[i].startDiceMovement();
    D[i].setTz(zoom);
    D[i].setSpeed(speedValue);
    D[i].drawDice();
    for (int i=0; i<3; i++){
    //start of loop
    if(i!=0){    
    if (D[0].getMoveLeft()==true){        
    if ( (D[0].getTx()>=D[i].getTx()-1.0f) && (D[0].getTx()<=D[i].getTx()) ){
    if (D[0].getMoveLeft()== true) D[0].setMoveLeft(false);
    else D[0].setMoveLeft(true);
    }else{
    if ( (D[0].getTx()-1<=D[i].getTx()) && (D[0].getTx()-1>=D[i].getTx()-1) ){
    if (D[0].getMoveLeft()== true) D[0].setMoveLeft(false);
    else D[0].setMoveLeft(true);
    if (D[0].getMoveUp()==true){        
    if ( (D[0].getTy()>=D[i].getTy()-1.0f) && (D[0].getTy()<=D[i].getTy()) ){
    if (D[0].getMoveUp()== true) D[0].setMoveUp(false);
    else D[0].setMoveUp(true);
    }else{
    if ( (D[0].getTy()-1<=D[i].getTy()) && (D[0].getTy()-1>=D[i].getTy()-1) ){
    if (D[0].getMoveUp()== true) D[0].setMoveUp(false);
    else D[0].setMoveUp(true);
    }//end of if i!=0
    if(i!=1){    
    if (D[1].getMoveLeft()==true){        
    if ( (D[1].getTx()>=D[i].getTx()-1.0f) && (D[1].getTx()<=D[i].getTx()) ){
    if (D[1].getMoveLeft()== true) D[1].setMoveLeft(false);
    else D[1].setMoveLeft(true);
    }else{
    if ( (D[1].getTx()-1<=D[i].getTx()) && (D[1].getTx()-1>=D[i].getTx()-1) ){
    if (D[1].getMoveLeft()== true) D[1].setMoveLeft(false);
    else D[1].setMoveLeft(true);
    if (D[1].getMoveUp()==true){        
    if ( (D[1].getTy()>=D[i].getTy()-1.0f) && (D[1].getTy()<=D[i].getTy()) ){
    if (D[1].getMoveUp()== true) D[1].setMoveUp(false);
    else D[1].setMoveUp(true);
    }else{
    if ( (D[1].getTy()-1<=D[i].getTy()) && (D[1].getTy()-1>=D[i].getTy()-1) ){
    if (D[1].getMoveUp()== true) D[1].setMoveUp(false);
    else D[1].setMoveUp(true);
    }//end of if i!=1
    if(i!=2){    
    if (D[2].getMoveLeft()==true){        
    if ( (D[2].getTx()>=D[i].getTx()-1.0f) && (D[2].getTx()<=D[i].getTx()) ){
    if (D[2].getMoveLeft()== true) D[2].setMoveLeft(false);
    else D[2].setMoveLeft(true);
    }else{
    if ( (D[2].getTx()-1<=D[i].getTx()) && (D[2].getTx()-1>=D[i].getTx()-1) ){
    if (D[2].getMoveLeft()== true) D[2].setMoveLeft(false);
    else D[2].setMoveLeft(true);
    if (D[2].getMoveUp()==true){        
    if ( (D[2].getTy()>=D[i].getTy()-1.0f) && (D[2].getTy()<=D[i].getTy()) ){
    if (D[2].getMoveUp()== true) D[2].setMoveUp(false);
    else D[2].setMoveUp(true);
    }else{
    if ( (D[2].getTy()-1<=D[i].getTy()) && (D[2].getTy()-1>=D[i].getTy()-1) ){
    if (D[2].getMoveUp()== true) D[2].setMoveUp(false);
    else D[2].setMoveUp(true);
    }//end of if i!=2
    //end of loop for i
    /** void display() Draw to the canvas. */
    // Purely a Java thing. Simple calls DrawGLScene once GL is Initialized
    public void display()
    for(int i=0;i<3;i++){
    glj.gljMakeCurrent(); //Ensure GL is initialised correctly
    DrawGLScene();
    glj.gljSwap(); //Swap buffers
    glj.gljFree(); // release GL
    // Key Listener events
    public void keyTyped(KeyEvent e){
    public void keyPressed(KeyEvent e){
    switch(e.getKeyCode())
    //Kill app
    case KeyEvent.VK_ESCAPE:
    System.exit(0);
    break;
    default :
    if(e.getKeyCode()<250) // only interested in first 250 key codes, are there more?
    keys[e.getKeyCode()]=true;     
    break;
    public void keyReleased(KeyEvent e){
    if(e.getKeyCode()<250) // only interested in first 250 key codes, are there more?
    keys[e.getKeyCode()]=false;
    // mouse listener events
    public void mouseEntered( MouseEvent evt )
    Component comp = evt.getComponent();
    if( comp.equals(this ) )
    //requestFocus();
    public void mouseExited( MouseEvent evt ){
    public void mousePressed( MouseEvent evt ){
    public void mouseReleased( MouseEvent evt ){
    public void mouseClicked( MouseEvent evt )
    Component comp = evt.getComponent();
    if( comp.equals(this ) )
    requestFocus();
    * Dice.java
    * Created on 08 February 2007, 22:26
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package longgong;
    import java.net.URL;
    import gl4java.GLContext;
    import gl4java.awt.GLAnimCanvas;
    import gl4java.utils.textures.*;
    * @author welcome
    public class Dice {
          GLAnimCanvas glCanvas ;
          URL codeBase;
          int[]texture1 = new int[1]; //Storage for one texture ( NEW )    
          int[]texture2 = new int[1]; //Storage for one texture ( NEW )    
          int[]texture3 = new int[1]; //Storage for one texture ( NEW )    
          int[]texture4 = new int[1]; //Storage for one texture ( NEW )    
          int[]texture5 = new int[1]; //Storage for one texture ( NEW )    
          int[]texture6 = new int[1]; //Storage for one texture ( NEW )    
          float rx;
          float ry;
          float rz;
          float tx;
          float ty;
          float tz;
          float speed;
          boolean txMoveLeft;
          boolean tyMoveUp;
          boolean tzMoveFront;
        /** Creates a new instance of Dice */
        public Dice(GLAnimCanvas g) {
            glCanvas = g;       
            if(!LoadGLTexture("c:\\java\\images\\one.png",texture1)){
                System.out.println("Failed to load Textures,Bailing!");
                System.exit(0);
            if(!LoadGLTexture("c:\\java\\images\\two.png",texture2)){
                System.out.println("Failed to load Textures,Bailing!");
                System.exit(0);
            if(!LoadGLTexture("c:\\java\\images\\three.png",texture3)){
                System.out.println("Failed to load Textures,Bailing!");
                System.exit(0);
            if(!LoadGLTexture("c:\\java\\images\\four.png",texture4)){
                System.out.println("Failed to load Textures,Bailing!");
                System.exit(0);
            if(!LoadGLTexture("c:\\java\\images\\five.png",texture5)){
                System.out.println("Failed to load Textures,Bailing!");
                System.exit(0);
            if(!LoadGLTexture("c:\\java\\images\\six.png",texture6)){
                System.out.println("Failed to load Textures,Bailing!");
                System.exit(0);
            txMoveLeft = true;
            tyMoveUp = true;
         public boolean inCircleBoundaries(float x, float y, float radius)
            float r;       
            r = (float)Math.sqrt((x*x) + (y*y));
            if (r <= radius)
                return  true;
            else
                return false;
        public void setCoordinates(float corRx,float corRy,float corRz,float corTx,float corTy,float corTz){
            rx = corRx;
            ry = corRy;
            rz = corRz;
            tx = corTx;
            ty = corTy;
            tz = corTz;
        public void getRandomDice(){
            int num = (int)(Math.random() * 6);
            if (num==1){
                rx=0.0f;
                ry=0.0f;
                rz=0.0f;
            else if (num==2){
                rx=90.0f;
                ry=0.0f;
                rz=0.0f;
            else if (num==3){
                rx=0.0f;
                ry=-90.0f;
                rz=0.0f;
            else if (num==4){
                rx=0.0f;
                ry=90.0f;
                rz=0.0f;
            else if (num==5){
                rx=-90.0f;
                ry=0.0f;
                rz=0.0f;
            else{
                rx=180.0f;
                ry=0.0f;
                rz=0.0f;
        public float getTx(){
            return tx+0.5f;
        public float getTy(){
            return ty+0.5f;
        public float getTz(){
            return tz+0.5f;
        public void setTz(float z){
            tz=z;
        public boolean getMoveLeft(){
            return txMoveLeft;
        public boolean getMoveUp(){
            return tyMoveUp;
        public void setMoveLeft(boolean m){
            txMoveLeft = m;
        public void setMoveUp(boolean m){
            tyMoveUp = m;
        public void startDiceMovement(){    
            if (txMoveLeft==true) {
                tx+=speed;           
            else {
                tx-=speed;
            if (tyMoveUp==true) {
                ty+=speed;
            else {
                ty-=speed;
            ry+=(speed*4);
            rx+=(speed*4);
            //rz+=(speed*2);
            //tx+=speed;
            //ty+=speed;
            //tz+=speed;             
         if (inCircleBoundaries(tx,ty,3.5f)==false) {  
            if (tx>=3.0f) txMoveLeft = false;
            if (tx<=-3.0f) txMoveLeft = true;
            if (ty>=3.0f) tyMoveUp = false;
            if (ty<=-3.0f) tyMoveUp = true;
        public void setSpeed(float s){
            speed = s;
         public void drawDice(){        
             glCanvas.gl.glLoadIdentity();                                             // Reset The View
             glCanvas.gl.glTranslatef(tx,ty,tz);
             glCanvas.gl.glRotatef(rx,1.0f,0.0f,0.0f);
             glCanvas.gl.glRotatef(ry,0.0f,1.0f,0.0f);
             glCanvas.gl.glRotatef(rz,0.0f,0.0f,1.0f);
             glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture1[0]);        
             glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);        
                // Front Face
             glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f,  1.0f);
             glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f,  1.0f);
             glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f,  1.0f,  1.0f);
             glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f,  1.0f,  1.0f);
             glCanvas.gl.glEnd();
             glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture6[0]);
             glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);        
               // Back Face          
             glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f, -1.0f);
             glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f,  1.0f, -1.0f);
             glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f,  1.0f, -1.0f);
             glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f, -1.0f);
             glCanvas.gl.glEnd();
             glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture2[0]);
             glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);        
                // Top Face
             glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f,  1.0f, -1.0f);
             glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f,  1.0f,  1.0f);
             glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f,  1.0f,  1.0f);
             glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f,  1.0f, -1.0f);
             glCanvas.gl.glEnd();
             glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture5[0]);
             glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);        
                // Bottom Face
             glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f, -1.0f);
             glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f, -1.0f);
             glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f,  1.0f);
             glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f,  1.0f);
             glCanvas.gl.glEnd();
             glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture3[0]);
             glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);        
                // Right face
             glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f, -1.0f);
             glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f,  1.0f, -1.0f);
             glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f( 1.0f,  1.0f,  1.0f);
             glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f( 1.0f, -1.0f,  1.0f);
             glCanvas.gl.glEnd();
             glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, texture4[0]);
             glCanvas.gl.glBegin(glCanvas.gl.GL_QUADS);        
                // Left Face
             glCanvas.gl.glTexCoord2f(0.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f, -1.0f);
             glCanvas.gl.glTexCoord2f(1.0f, 0.0f); glCanvas.gl.glVertex3f(-1.0f, -1.0f,  1.0f);
             glCanvas.gl.glTexCoord2f(1.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f,  1.0f,  1.0f);
             glCanvas.gl.glTexCoord2f(0.0f, 1.0f); glCanvas.gl.glVertex3f(-1.0f,  1.0f, -1.0f);
             glCanvas.gl.glEnd();
          public boolean LoadGLTexture(String fileName, int textureNumber[])
             PngTextureLoader texLoader = new PngTextureLoader(glCanvas.gl, glCanvas.glu);
             if(codeBase!=null)  
                texLoader.readTexture(codeBase, fileName);
             else
                texLoader.readTexture(fileName);
             if(texLoader.isOk())
                //Create Texture
                glCanvas.gl.glGenTextures(1, textureNumber);
                glCanvas.gl.glBindTexture(glCanvas.gl.GL_TEXTURE_2D, textureNumber[0]);
                glCanvas.gl.glTexParameteri(glCanvas.gl.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    ill attach 4 files that needs to be
    enhanced or debug for possible errors. i hate to break it to you, but even if you post this for the seventh time, finding and fixing errors in your code remains your task.

  • Running a Java application from a Swing GUI

    Hi,
    I was wondering if there is a simple way to run a Java application from a GUI built with Swing. I would presume there would be, because the Swing GUI is a Java application itself, technically.
    So, I want a user to click a button on my GUI, and then have another Java application, which is in the same package with the same classpaths and stuff, run.
    Is there a simple way to do this? Do any tutorials exist on this? If someone could give me any advice, or even a simple "yes this is possible, and it is simple" or "this is possible, but difficult" or "no this is not possible" answer, I would appreciate it. If anyone needs more information, I'll be happy to provide it.
    Thanks,
    Dan

    I don't know if it is possible to run the main method from another Java app by simply calling it...
    But you could just copy and paste the stuff from your main method into a new static method called something like runDBQuery and have all the execution run from there.
    How does that sound? Is it possible?
    What I'm suggeting is:
    Original
    public class DBQuery{
    public static void methodA(){
    public static void doQuery(){
    methodA();
    public static void main(String[] args){
    // Your method calls
    //Your initializing
    doQuery();
    }Revised:
    public class DBQuery{
    public static void methodA(){
    public static void doQuery(){
    methodA();
    public static void doMyQuery(){
    // Your method calls
    //Your initializing
    doQuery();
    // No main needed!!
    //public static void main(String[] args){
    // Your method calls
    //doQuery();
    //}

  • Creating file browser GUI using java swing tree

    Hi all,
    I have some questions which i wish to clarify asap. I am working on a file browser project using java swing. I need to create 2 separate buttons. 1 of them will add a 'folder' while the other button will add a 'file' to the tree when the buttons are clicked once. The sample source code known as 'DynamicTreeDemo' which is found in the java website only has 1 add button which is not what i want. Please help if you know how the program should be written. Thx a lot.
    Regards,

    Sorry, don't know 'DynamicTreeDemo'import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    import java.io.File;
    public class Test extends JFrame {
      JTree jt = new JTree();
      DefaultTreeModel dtm = (DefaultTreeModel)jt.getModel();
      JButton newDir = new JButton("new Dir"), newFile = new JButton("new File");
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        newDir.setEnabled(false);
        newFile.setEnabled(false);
        jt.setShowsRootHandles(true);
        content.add(new JScrollPane(jt), BorderLayout.CENTER);
        File c = new File("C:\\temp");
        DefaultMutableTreeNode root = new DefaultMutableTreeNode(c);
        dtm.setRoot(root);
        addChildren(root);
        jt.addTreeSelectionListener(new TreeSelectionListener() {
          public void valueChanged(TreeSelectionEvent tse) { select(tse) ; }
        JPanel jp = new JPanel();
        content.add(jp, BorderLayout.SOUTH);
        jp.add(newDir);
        jp.add(newFile);
        newDir.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            TreePath tp = jt.getSelectionPath();
            if (tp!=null) {
              DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)tp.getLastPathComponent();
              File newFile = new File((File)dmtn.getUserObject(),"foo");
              if (newFile.mkdir()) {
                dmtn.add(new DefaultMutableTreeNode(newFile));
                dtm.nodeStructureChanged(dmtn);
              } else System.out.println("No Dir");
        newFile.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            TreePath tp = jt.getSelectionPath();
            if (tp!=null) {
              DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)tp.getLastPathComponent();
              File newFile = new File((File)dmtn.getUserObject(),"foo.txt");
              try {
                if (newFile.createNewFile()) {
                  dmtn.add(new DefaultMutableTreeNode(newFile));
                  dtm.nodeStructureChanged(dmtn);
                } else System.out.println("No File");
              catch (java.io.IOException ioe) { ioe.printStackTrace(); }
        setSize(300, 300);
        setVisible(true);
      void select(TreeSelectionEvent tse) {
        TreePath tp = jt.getSelectionPath();
        newDir.setEnabled(false);
        newFile.setEnabled(false);
        if (tp!=null) {
          DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)tp.getLastPathComponent();
          File f = (File)dmtn.getUserObject();
          if (f.isDirectory()) {
            newDir.setEnabled(true);
            newFile.setEnabled(true);
      void addChildren(DefaultMutableTreeNode parent) {
        File parentFile = (File)parent.getUserObject();
        File[] children = parentFile.listFiles();
        for (int i=0; i<children.length; i++) {
          DefaultMutableTreeNode child = new DefaultMutableTreeNode(children);
    parent.add(child);
    if (children[i].isDirectory()) addChildren(child);
    public static void main(String[] args) { new Test(); }

Maybe you are looking for

  • Where clause is not being passed to the report

    I just upgraded my crystal reports from 10.0 to 11 R2. Reports were working fine in 10.0 version, Reports are called from vb.net (vissual studio 2005). When I was running this reports using crystal 10.0 and visual studio 2005, it was working fine, Af

  • How to set the language key in Sales document header text?

    Hi Guys, When I am creating a sales order I found in the header text tab only three languages English, Thai and Ukranian are mentained.. So can you please tell me how to add/ delete more language keys in language key field in a step by step process??

  • No one wants my Performance Tuning experience?

    I worked as a DBA for 2 years in IT major where my work was confined to Performance Tuning & monitoring and so I had no opportunity to get the experience of Backup & Recovery,RMAN and other Core DBA responsibilities. I had to leave in July last year

  • Lost iPod touch. How can i get it back? *never setted up findmyipod? is there hope

    I lost my ipod two fridays ago, ive looked everywhere in my house for it. I had a track meet that day and had it with me when i went. I had it in my bag and when i got home it wasnt in my bag at all. it either fell out, got stolen, or fell out then s

  • Photoshop Elements &IMac/Snow Leopard

    I have had Photshop Elements 3.0 installed on my Imac running on Leopard and it has been problem free. I have recently installed Snow Leopard  and now I am having problems opening some photos from IPhoto. When I have Iphoto set to edit in Elements bu