Beginners swing help

Hi, Im reading a beginners tutorial to swing located on this site.
import javax.swing.*;
public class HelloWorldSwing {
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Hello World bla blah blah");
JButton button = new JButton("Iam A BUTTON");
          int width = 300;
          int height = 300;
     frame.setSize(width, height);
     frame.pack();
frame.setVisible(true);
          JPanel panel = new JPanel(new GridLayout(0,1));
          panel.add(button);
          panel.add(label);
          panel.setBorder(BorderFactory.createEmptyBorder());
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
     public void run() {
     createAndShowGUI();
This is the code I am using, since I tryed to make the Jpanel I get this error when I try to compile it
HelloWorldSwing.java:20: cannot find symbol
symbol : class GridLayout
location: class HelloWorldSwing
          JPanel panel = new JPanel(new GridLayout(0,1));
^
1 error
Can anyone tell me why? thanks

import java.awt.GridLayout;

Similar Messages

  • Swing Help!!

    Is there some sort of class or something that can allow me to make an expander in swing? Im not really sure the technical name for it so i have done a little example of what i mean below.
    +great
    +really good
    when great is pressed it expands to:
    -great
    brilliant
    +really good
    Any help would be much appreciated.
    Edited by: markyboos on Mar 30, 2008 7:36 AM

    How about a JTree?
    [API link here|http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html]
    [Tutorial link here|http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html]

  • Displaying 4 Text Areas in Swing.Help required.

    Folks
    I need to define 4 Text Areas in Swing in the following pattern:
    1 -- 2
    3 -- 4
    where 1,2 3 and 4 are TextAreas,
    As of now I can get 2 text Areas :1 and 3 only by the following code:
    public class 4TextAreas extends JFrame
    private Container c;
    Box b = Box.createVerticalBox();
    msgTextArea = new JTextArea(10,15);
    b.add(new JScrollPane(msgTextArea));
    msgTextArea_2 = new JTextArea(10,15);
    b.add(new JScrollPane(msgTextArea_2));
    c = getContentPane();
    c.add(b);
    setSize(250,250);
    this.show();
    Please can any one help as to how to get TextArea 2 and 4 please.
    Do I need to crate another Box object called b1?
    Please reply.

    You could try creating two vertical boxes, adding two textareas to each and then add the vertical boxes to a horizontal box. ( or two horizontals to a vertical, of course).
    Also you could try a different layout manager such as a gridlayout or gridbaglayout.
    Cheers
    DB

  • Displaying a matrix in swing----HELP!! :)

    Hello I want to print out values from a matrix in some sort of table.
    javax.swing.JTable is almost what I want, but you can't do row labels (only column labels, I think)--
    Are there any classes like JTable, but a little more like an Excel spreadsheet where you have labels on the columns and rows???
    Or any other suggestions for displaying matrix values with swing would be helpful!!
    THANKS!!!!

    .

  • Thread in Swing help please

    Hey gang, I am relatively new to Java world, and especially to swing and thread. I am trying to build an application with a main dashboard, where the users can click on a button and parse a text file. However, if there were an error in the file, I would like to stop paring the file, but not exit the application once there is an error. I don?t know quite how to stop the process without using System.exit(0); When I use System.exit(0); needless to say my main dashboard exits also, which I want to avoid.
    I was told to use threads by my friends, but I trying reading up on SwingWorker class found on the website to help with threads (at least I think so). I am still very lost. If there is any more clarification needed, please let me know

    Your problem has nothing to do with threads. As "kulkarni_ash" wrote, you need to surround code which crashes with try{ }catch(Throwable t}{...}. Most runtime problems are reported by throwing an exception, which is understood as "abrubtly abort code execution and gracefully return to closest enclosing catch". There is many exceptions classes, each tided to specific kind of error. Throwable is most general one, and you should not use it usually.
    Threads, on other hand are used only, if you expect to have a lot of work to be done and like to have it done "in background" what leaves user interface alive. Example is printing - without thread user interface will freez until last page is printed - with printing thread user may click cancel to abort printing.

  • Java.io and java.swing help

    i'm writing a program that write the byte representation of numbers and outputs them to a joptionpane window
    it keeps telling me that void functions are not allowed
    is there any way that i can use void functions in my output? or would i need to change to a method that returns a value?
    here is my code, please help me, it will be greatly appreciated :)
    GUI Part
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class zero2nineTest extends JFrame{
         zero2nine show;
         public static void main(String[] args){
              zero2nineTest x = new zero2nineTest();
              x.setVisible(true);
         public zero2nineTest(){
              super("File IO and Byte Representation Tests");
              Container cp = getContentPane();
              cp.setLayout(new FlowLayout());
              JButton readFile1 = new JButton("Create and Read 1st Byte Representations");
              readFile1.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                        zero2nine.writeFile(out);
                        JOptionPane.showMessageDialog(
                             zero2nineTest.this,
                             "Odd numbers: " + zero2nine.readFile(), "Byte Representation of Odd Numbers",
                             JOptionPane.PLAIN_MESSAGE);
                   cp.add(readFile1);
              JButton readFile2 = new JButton("Create and Read 2nd Byte Representations");
              readFile1.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                        zero2nine.writeFile2(out);
                        JOptionPane.showMessageDialog(
                             zero2nineTest.this,
                             "Even numbers: " + zero2nine.readFile2(), "Byte Representation of Even Numbers",
                             JOptionPane.PLAIN_MESSAGE);
                   cp.add(readFile2);
              JButton quit = new JButton("Quit Program");
              quit.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                        int decision;
                        decision = JOptionPane.showConfirmDialog(
                             null, "Are you sure?", "Are you sure?", JOptionPane.YES_NO_OPTION);
                             if(decision == 0){
                                  System.exit(0);
                   cp.add(quit);
                   pack();
    Class Part
    import java.io.*;
    class zero2nine{
         static String fileName = "zero2nine.txt";
    //     public static void main(String[] args){
    //          try{
    //               FileOutputStream out = createFile();
    //               writeFile(out);
    //               writeFile2(out);
    //               readFile();
    //               readFile2();
    //          }catch(IOException io){
    //               System.out.println("closing program");
         static FileOutputStream createFile() throws IOException{
              File f = new File(fileName);
              FileOutputStream out = new FileOutputStream(f);
              return out;
         static void writeFile(FileOutputStream out) throws IOException{
              DataOutputStream ds = null;
              try{
                   ds = new DataOutputStream(out);
                   int x = 0;
                   for(int i = 0; i < 10; i++){
                        x = i * i;
                        ds.writeInt(x);
              }finally{
                   System.out.println("File written this far");
         static void writeFile2(FileOutputStream out) throws IOException{
              DataOutputStream ds = null;
              try{
                   ds = new DataOutputStream(out);
                   int x = 0;
                   for(int i = 10; i < 20; i++){
                        x = i * i;
                        ds.writeInt(x);
              }finally{
                   System.out.println("File written this far again");
         public int readFile() throws IOException{
              DataInputStream dataIn = null;
              try{
                   FileInputStream in = new FileInputStream("zero2nine.txt");
                   dataIn = new DataInputStream(in);
                   //Output odd numbers
                   for(int i = 0; i < 10; i++){
                        if(dataIn.readInt() % 2 == 0){
                             int b = dataIn.readInt();
                             System.out.println(b);
              }finally{
                   System.out.println("File read this far");
                   return(b);
         static void readFile2() throws IOException{
              DataInputStream dataIn = null;
              try{
                   FileInputStream in = new FileInputStream("zero2nine.txt");
                   dataIn = new DataInputStream(in);
                   //Output even numbers
                   for(int i = 10; i < 20; i++){
                        if(dataIn.readInt() % 2 == 1){
                             int b = dataIn.readInt();
                             System.out.println(b);
              }finally{
                   System.out.println("File read this far again");
    }

    F:\Computer Science\Java\zero2nineTest.java:28: cannot resolve symbol
    symbol: variable out
                        zero2nine.writeFile(out);
    ^
                   public void actionPerformed(ActionEvent e){
                        zero2nine.writeFile(out);
                        JOptionPane.showMessageDialog(
    F:\Computer Science\Java\zero2nineTest.java:31: 'void' type not allowed here
                             "Odd numbers: " + zero2nine.readFile(), "Byte Representation of Odd Numbers",
    ^
                             zero2nineTest.this,
                             "Odd numbers: " + zero2nine.readFile(), "Byte Representation of Odd Numbers",
                             JOptionPane.PLAIN_MESSAGE);
    F:\Computer Science\Java\zero2nineTest.java:41: cannot resolve symbol
    symbol: variable out
                        zero2nine.writeFile2(out);
    ^
                        zero2nine.writeFile2(out);
                        JOptionPane.showMessageDialog(
                             zero2nineTest.this,
    F:\Computer Science\Java\zero2nineTest.java:44: 'void' type not allowed here
                             "Even numbers: " + zero2nine.readFile2(), "Byte Representation of Even Numbers",
    ^
                             zero2nineTest.this,
                             "Even numbers: " + zero2nine.readFile2(), "Byte Representation of Even Numbers",
                             JOptionPane.PLAIN_MESSAGE);
    4 errors
    Tool completed with exit code 1

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

  • Need swing help

    I'm having a lot of troble with a java project i am doing for school. We have to make this word matching type game, and I'm unable to get the icons to repaint correctly. More specifically they will not show up on load, but if i resize the window they display correctly, they will also not refresh when the state of the game changes. I've pasted all the code that relates to drawing bellow, any help would be very apreciated. Thank you.
    //package Phase2;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Draw extends JFrame
         private Loader _loader;
         private java.util.LinkedList<GTile> _column1;
         private java.util.LinkedList<GTile> _column2;
         private java.util.LinkedList<GTile> _column3;
         private java.util.LinkedList<GTile> _column4;
         private java.util.LinkedList<GTile> _column5;
         private java.util.LinkedList<GTile> _column6;
         private java.util.LinkedList<GTile> _column7;
         private java.util.ArrayList<String> _arrayList;
         private java.util.ArrayList<java.util.LinkedList<GTile>> _2DArray;
         //private java.util.ArrayList<Picture> _pictures;
         private GamePanel GameBoard;
         private GameState _gsObj;
         public Draw(GameState arg_gsObj)
              super("Bookworm Group 4");
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              _loader = new Loader();
              _gsObj = arg_gsObj;
              _column1 = new java.util.LinkedList<GTile>();
              _column2 = new java.util.LinkedList<GTile>();
              _column3 = new java.util.LinkedList<GTile>();
              _column4 = new java.util.LinkedList<GTile>();
              _column5 = new java.util.LinkedList<GTile>();
              _column6 = new java.util.LinkedList<GTile>();
              _column7 = new java.util.LinkedList<GTile>();
              _2DArray = new java.util.ArrayList<java.util.LinkedList<GTile>>();
              establishArrays();
              GameBoard = new GamePanel(_2DArray, _gsObj, _loader);
              getContentPane().add(GameBoard, BorderLayout.CENTER);
              setVisible(true);
              pack();
              show();
              paintComponents(this.getGraphics());
              //resize( 500, 500 );
         public void establishArrays()
              for(int i=0; i<8; i++)
                   _column1.add(_loader.Send(1, i));
              for(int i=0; i<7; i++)
                   _column2.add(_loader.Send(2 ,i));
              for(int i=0; i<8; i++)
                   _column3.add(_loader.Send(3, i));
              for(int i=0; i<7; i++)
                   _column4.add(_loader.Send(4, i));
              for(int i=0; i<8; i++)
                   _column5.add(_loader.Send(5, i));
              for(int i=0; i<7; i++)
                   _column6.add(_loader.Send(6, i));
              for(int i=0; i<8; i++)
                   _column7.add(_loader.Send(7, i));
              _2DArray.add(_column1);
              _2DArray.add(_column2);
              _2DArray.add(_column3);
              _2DArray.add(_column4);
              _2DArray.add(_column5);
              _2DArray.add(_column6);
              _2DArray.add(_column7);
         public void update(Graphics g)
              super.update(g);
              System.out.println("update called");
              Graphics2D g2d = (Graphics2D)g;
              GameBoard.update(g2d);
         //     g2d.drawImage(_image, 0, 0, null);
         public void repaint()
              super.repaint();
              System.out.println("Draw repaint called");
              //Graphics2D g2d = (Graphics2D)this.getGraphics();
         //     g2d.drawImage(_image, 0, 0, null);
         public void paint(Graphics g)
              super.paint(g);
              System.out.println("Draw Paint called");
              System.out.println("Draw: "+this.getGraphics());
              System.out.println(g);
              Graphics2D g2d = (Graphics2D)g;
              GameBoard.update(g2d);
         //     g2d.drawImage(_image, 0, 0, null);
    /package Phase2;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    class GamePanel extends JPanel
         private GameColumn _column1;
         private GameColumn _column2;
         private GameColumn _column3;
         private GameColumn _column4;
         private GameColumn _column5;
         private GameColumn _column6;
         private GameColumn _column7;
         private GameState _gsObj;
         private Loader _loader;
         java.util.ArrayList<GTile> _selectedTiles;
         java.util.ArrayList<java.util.LinkedList<GTile>> _cArray;
         public GamePanel(java.util.ArrayList<java.util.LinkedList<GTile>> arg_array, GameState arg_gsObj, Loader arg_loader)
              super();
              _cArray = arg_array;
              _gsObj = arg_gsObj;
              _loader = arg_loader;
              _selectedTiles = new java.util.ArrayList<GTile>();
              GridLayout board = new GridLayout(1,7);
              setLayout(board);
              buildColumns();
              setVisible(true);
              this.setBackground(java.awt.Color.WHITE);               
         public void buildColumns()
              _column1 = new GameColumn(_cArray.get(0), 1, this);
              _column2 = new GameColumn(_cArray.get(1), 2, this);
              _column3 = new GameColumn(_cArray.get(2), 3, this);
              _column4 = new GameColumn(_cArray.get(3), 4, this);
              _column5 = new GameColumn(_cArray.get(4), 5, this);
              _column6 = new GameColumn(_cArray.get(5), 6, this);
              _column7 = new GameColumn(_cArray.get(6), 7, this);
              add(_column1);
              add(_column2);
              add(_column3);
              add(_column4);
              add(_column5);
              add(_column6);
              add(_column7);
              System.out.println("gamePanel: "+this.getGraphics());
         public void paint(Graphics g)
              GTile temp = new GTile("z");
              for(int i=0; i<8; i++)
                   temp = _column1.getTile(i);
                   temp.repaint();
              for(int i=0; i<7; i++)
                   temp = _column2.getTile(i);
                   temp.repaint();
              for(int i=0; i<8; i++)
                   temp = _column3.getTile(i);
                   temp.repaint();
              for(int i=0; i<7; i++)
                   temp = _column4.getTile(i);
                   temp.repaint();
              for(int i=0; i<8; i++)
                   temp = _column5.getTile(i);
                   temp.repaint();
              for(int i=0; i<7; i++)
                   temp = _column6.getTile(i);
                   temp.repaint();
              for(int i=0; i<8; i++)
                   temp = _column7.getTile(i);
                   temp.repaint();
        public void follow(GTile arg_tile)
             System.out.println("heres a tile "+arg_tile.getColumn()+" "+arg_tile.getPos());
             if(!_selectedTiles.isEmpty())
                  GTile lastTile = _selectedTiles.get(0);
                  System.out.println("last tile "+lastTile.getColumn()+" "+lastTile.getPos());
                  if(arg_tile.getColumn() == lastTile.getColumn() && arg_tile.getPos() == lastTile.getPos())
                       if(_gsObj.Submit(_selectedTiles))
                            this.removeTiles(_selectedTiles);
                       _selectedTiles.clear();
                  }else if(this.adjacent(arg_tile))
                       _selectedTiles.add(0, arg_tile);
                  }else
                       _selectedTiles.clear();
                       _selectedTiles.add(0, arg_tile);
             }else
                  _selectedTiles.add(0, arg_tile);
        private void removeTiles(java.util.ArrayList<GTile> arg_deadTiles)
             for(int i = 0; i<arg_deadTiles.size(); i++)
                  GTile tempTile = arg_deadTiles.get(i);
                  int column = tempTile.getColumn() - 1;
                  java.util.LinkedList<GTile> tempColumn = _cArray.get(column);
                  for(int k = tempTile.getPos(); k >0; k--)
                       tempColumn.set(k, tempColumn.get(k-1));
                  tempColumn.set(0, _loader.Send(column, 0));
                  _cArray.set(column, tempColumn);
             this.removeAll();
             this.buildColumns();
             System.out.println(this.getGraphics());
             this.update(this.getGraphics());
             System.out.println("\n\n\n");
             //this.resize(500, 500);
        private boolean adjacent(GTile arg_tile)
             if(!_selectedTiles.isEmpty())
                  GTile lastTile = _selectedTiles.get(0);
                  System.out.println("modulus"+arg_tile.getColumn()%2);
                  if(arg_tile.getColumn()%2 == 1)
                       System.out.println("this is a 7 tile column"+arg_tile.getColumn()%2);
                       if(arg_tile.getColumn() == lastTile.getColumn())
                            if( arg_tile.getPos()+1 == lastTile.getPos() || arg_tile.getPos()-1 == lastTile.getPos())
                                 return true;
                            }else
                                 return false;
                       }else if(arg_tile.getColumn()+1 == lastTile.getColumn())
                            if( arg_tile.getPos()-1 == lastTile.getPos() || arg_tile.getPos() == lastTile.getPos())
                                 return true;
                            }else
                                 return false;
                       }else if(arg_tile.getColumn()-1 == lastTile.getColumn())
                            if( arg_tile.getPos()-1 == lastTile.getPos() || arg_tile.getPos() == lastTile.getPos())
                                 return true;
                            }else
                                 return false;
                       }else
                            return false;
                  }else
                       if(arg_tile.getColumn() == lastTile.getColumn())
                            if( arg_tile.getPos()+1 == lastTile.getPos() || arg_tile.getPos()-1 == lastTile.getPos())
                                 return true;
                            }else
                                 return false;
                       }else if(arg_tile.getColumn()+1 == lastTile.getColumn())
                            if( arg_tile.getPos()+1 == lastTile.getPos() || arg_tile.getPos() == lastTile.getPos())
                                 return true;
                            }else
                                 return false;
                       }else if(arg_tile.getColumn()-1 == lastTile.getColumn())
                            if( arg_tile.getPos()+1 == lastTile.getPos() || arg_tile.getPos() == lastTile.getPos())
                                 return true;
                            }else
                                 return false;
                       }else
                            return false;
             return false;
    //package Phase2;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    class GameColumn extends JPanel
         private java.util.LinkedList<GTile> _tArray;
         private int _cnumber;
         private GamePanel _gpObj;
         public GameColumn(java.util.LinkedList<GTile> arg_tArray, int arg_cnumber, GamePanel arg_gpObj)
              super();
              _cnumber = arg_cnumber;
              _tArray = arg_tArray;
              _gpObj = arg_gpObj;
              int height = _tArray.size();
              GridLayout cLayout = new GridLayout(height, 1);
              setLayout(cLayout);
              for(int i=0; i<height; i++)
                   GTile temp = _tArray.get(i);
                   temp.setGP(_gpObj);
                   System.out.println(_tArray.get(i)._gpObj);
                   add(_tArray.get(i));
              if(height == 7)
                   float tempY = 15;
                   setAlignmentY(tempY);
              setVisible(true);
              this.setBackground(java.awt.Color.WHITE);
              System.out.println("gamecolumn: "+this.getGraphics());
         public GTile getTile(int arg_pos)
              return _tArray.get(arg_pos);
         public int GetSize()
              return _tArray.size();
         public void paint(Graphics comp)
              super.paint(comp);
              GTile tempTile = new GTile("x");
              int height = _tArray.size();
              for(int i=0; i<height; i++)
                   tempTile = _tArray.get(i);
                   tempTile.paintComponent(comp);
    //package Phase2;
    import java.awt.*;
    import java.awt.Graphics2D;
    import javax.swing.event.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.geom.AffineTransform;
    public class GTile extends JComponent
         private String _letter;
         private int _column;
         private int _pos;
         public GamePanel _gpObj;
         private Image _image;
         private Graphics2D DDGraphic;
         public GTile(String arg_letter)
              super();
              _letter = arg_letter;
              _column = 0;
              _pos = 0;
              _image = new ImageIcon("Pictures/"+_letter+".GIF").getImage();
              this.setMinimumSize(new Dimension(30,30));
              this.setMaximumSize(new Dimension(30,30));
              this.setBackground(java.awt.Color.WHITE);
              this.addMouseListener(new MouseAdapter()
                   public void mouseClicked(MouseEvent e){
                             handleClick();
                   public void mousePressed(MouseEvent e){
                             //setCurrent(e);
                   public void mouseReleased(MouseEvent e){
                             //releaseCurrent();
              setVisible(true);
         public void setPos(int arg_column, int arg_pos )
              _column = arg_column;
              _pos = arg_pos;
         public void setGP(GamePanel arg_gpObj)
              _gpObj = arg_gpObj;
         public int getColumn()
              return _column;
         public int getPos()
              return _pos;
         public String getLetter()
              return _letter;
         public void handleClick()
              GTile temp = this;
              System.out.println("we got anything here?");
              _gpObj.follow(temp);
         public void paint(Graphics g)
              super.paint(g);
              if(_letter.equals("A"))
                   System.out.println("\npos "+_pos+" col "+_column);
                   System.out.println("Paint called");
                   System.out.println(g);
              Graphics2D g2d = (Graphics2D)g;
              g2d.drawImage(_image, 0, 0, null);
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              Graphics2D g2d = (Graphics2D)g;
              if(_letter.equals("A"))
                   System.out.println("\npos "+_pos+" col "+_column);
                   System.out.println("paintComponet called");
                   System.out.println(g);
                   System.out.println(this.getGraphics());
              g2d.drawImage(_image, 0, 0, null);
              //_image.paintIcon(this, DDGraphic, 0, 0);
              setVisible(true);
              

    Well, I would start by reading the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html]How to Use Icons. The easiest way is to just add the icon to a JLabel.
    You code is full of overrides. There should be no need to override methods like "update, paint, repaint" of your main JFrame. Even the panels you use override the paint method. Although I strongly doubt you need to override the paint() method, the correct way to override the painting is by overriding the paintComponent(..) method.
    I would suggest you don't need any of your override logic. Instead you just replace the icon of each JLabel by using setIcon.

  • Netbeans swing help!

    hello,
    I am creating one GUI project using swing using netbeans 4.1 in windows environment. It works fine and display the GUI correctly.
    But, my problem is when I use that project in linux that is when I open this project folder using netbeans 4.1 linux version, it compile and execute.
    But], when GUI open, the label leters are not shown properly. it shows S.... in the GUI window. also, the gui some time struck. the radio buttons not works some time.
    what can I do. in linux.
    shall i need to change in gui layout setting or others.
    pls, help me to solve this problem.
    thank you.

    Maybe you should read the responses to your other threads on this topic!
    http://forum.java.sun.com/thread.jspa?threadID=767912&messageID=4377241#4377241
    http://forum.java.sun.com/thread.jspa?threadID=767960&messageID=4377468#4377468

  • Professional Swing Help

    Hi,
    I have developed a Swing-based GUI and although the tool works functionally, I am looking for some improvements in the actual GUI components' layout - basically I want to have some beautification done on the existing GUI. I think this kind of do-it-pretty task can be handled very easily by a Swing expert and so I was checking if anybody is available professionally to take on this task and make this happen? Let me know if there is anyone interested in this and we can go from there.
    Thanks

    discuss2008
    Please don't advertise for paid help here. I'm blocking your post.
    db

  • Question on swings help me

    Hi to all i am new to swings concept my problem is
    I taken 8 subjects with 100 marks and 5 labs with 75 marks in my application.
    Know my problem is when i am calculating subjects and labs i am not getting average .
    And but when i am calculate total divided by 13 i am getting average.
    For example : 8 subjects total is 560.
    5 labs total is 250.
    average = total/13
    i am getting average.
    But i want average like this i.e average = total /1175;
    i am taken total = subjects + labs;
    help me regarding this topic
    Thanks in advance

    Hello
    u r did "average = total/13; " this avg is not correct one .....
    bcos 8 subj is respect to 100 and remaining is respect to 75 .
    avg = (getting total marks / totalmarks)*100
    this is the correct way to calculate avg
    i am taken total = subjects + labs;
    all the best
    regards
    Amir

  • Errors- Runtime() in Swing Help

    Hi, Iam trying to use Runtime() in Swing..iam getting nonsense errors what have i missed?
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class appSrunCommand extends JApplet implements Runnable,ActionListener{
         JLabel l1;
         JTextField tf;
         JButton run;
         JTextArea ta;
         JScrollPane jsp;
         String[] cmd = new String[4];
              public void init(){
                   l1 = new JLabel("Enter the command");
                   tf = new JTextField(10);
                   run = new JButton("Run");
                   ta = new JTextArea(20,20);
                   //jsp = getConentPane();
                   run.addActionListener(this);
                        Container con = getContentPane();
                        con.setLayout(new FlowLayout());
                        con.add(l1);con.add(tf);con.add(run);
                        con.add(ta);
                        public void actionPerformed(ActionEvent e){
                             String comm = tf.getText();
                             cmd[0]= "appSrunCommand";
                             cmd[1] = "cmd.exe";
                             cmd[2] = "/C";
                             cmd[3] = comm;
                             try{
                                  Runtime rn = Runtime.getRuntime();
                                  String temp = "";
                                  ta.setText(String.valueOf("Executing "+ cmd[0]+" "+cmd[1]+" "+cmd[2]+" "+cmd[3]));
                                  Process p = rn.exec(cmd);
                                  int exitVal = rn.waitFor();
                                  ta.setText(String.valueOf(exitVal));
                                  // any error message?
                StreamGobbler errorGobbler = new
                    StreamGobbler(rn.getErrorStream(), "ERROR");           
                // any output?
                StreamGobbler outputGobbler = new
                    StreamGobbler(rn.getInputStream(), "OUTPUT");
                // kick them off
                errorGobbler.start();
                outputGobbler.start();
                // any error???
                //int exitVal = rn.waitFor();
                             catch(Throwable t){
                                  ta.setText(String.valueOf(t));
    class StreamGobbler extends Thread{
                   InputStream is;
                   String type;
              //     Thread t = new Thread(this);
              //     t.start();
                        StreamGobbler(InputStream is,String type){
                             this.is = is;
                             this.type = type;
                                  public void run(){
                                       try{
                                            BufferedReader br = new BufferedReader( new InputStreamReader());
                                            String line = null;
                                            while((br.readLine())!= null)
                                            //ta.setText(String.valueOf(type+">"+ line));
                                            System.out.println(type+">"+line);
                                       catch(IOException ioe){}
                                       //     ta.setText(String.valueOf(ioe));
              Here are the errors..
    --------------------Configuration: <Default>--------------------
    C:\j2sdk\bin\appSrunCommand.java:11: appSrunCommand is not abstract and does not override abstract method run() in java.lang.Runnable
    public class appSrunCommand extends JApplet implements Runnable,ActionListener{
           ^
    C:\j2sdk\bin\appSrunCommand.java:45: cannot resolve symbol
    symbol  : method waitFor ()
    location: class java.lang.Runtime
                                                    int exitVal = rn.waitFor();
                                                                    ^
    C:\j2sdk\bin\appSrunCommand.java:49: cannot resolve symbol
    symbol  : method getErrorStream ()
    location: class java.lang.Runtime
                    StreamGobbler(rn.getErrorStream(), "ERROR");           
                                    ^
    C:\j2sdk\bin\appSrunCommand.java:53: cannot resolve symbol
    symbol  : method getInputStream ()
    location: class java.lang.Runtime
                    StreamGobbler(rn.getInputStream(), "OUTPUT");
                                    ^
    C:\j2sdk\bin\appSrunCommand.java:80: cannot resolve symbol
    symbol  : constructor InputStreamReader ()
    location: class java.io.InputStreamReader
                                                                    BufferedReader br = new BufferedReader( new InputStreamReader());
                                                                                                            ^
    5 errors
    Process completed.

    appSrunCommand is not abstract and does not override abstract method run() in java.lang.RunnableThis error message doesn't only tell you what's wrong, it also gives you hints about how to fix it. Why don't you read the messages?

  • Immdiate swing help

    can anyone tell me about swing archectecture. And currently how many packages does swing support.

    http://java.sun.com/docs/books/tutorial/uiswing/

  • Beginners wireless help sought

    Hi, I have a flat panel iMac with cable broadband running Tiger. I want to set up a wireless connection which can be shared with a windows laptop...
    I'm an absolute beginner with wireless...where do I start?! eg will any wireless router be compatible?
    Many thanks for any help!
    G4 iMac   Mac OS X (10.4.7)  

    moon_goddess, 
    Greetings from Wiltshire (where I work).
    Firstly, do you already have a broadband provider? If not then when you choose one ask that they provide a wireless router (most will charge a small fee for this - but it's usually cheaper than buying the router seperately).
    If you already have a Broadband connection you need to get yourself a Wireless Router to connect your current broadband modem to. These can be bought in any PC World, Staples or widely available on the internet. Some broadband modems are USB and so both undesirable for Mac use and won't connect to a Router. You may prefer to buy a combined modem/router which reduces the electrical sockets and cables required.
    Next you need to decide how to connect your iMac:
    Ethernet - just use the supplied Ethernet cable which comes with the Router.
    Wireless - use the Airport Card in your Mac. To see if you have one installed go to Apple Menu > About this Mac > More Info > Airport.
    If will also help if you could post your processor speed which can be found in the same way.
    I recently posted this diagram for another thread but it applies to you to.
    Any router should be fine and will work exactly the same with a PC as a Mac (WiFi is an international standard (802.11)).
    regards
    mrtotes

Maybe you are looking for

  • IPod Touch 5th Gen NO SOUND!!!!!!

    My iPod 5th gen displays & seems to be running but it has no sound, but the sound is perfectly fine when im using earphones. I have tried the reset and/or restore but doesnt change a thing, I think this happened 2 weeks after updating to iOS 7, i don

  • Purchase Requisition transfer  - Queue issue

    Hello! Regarding the Purchase Requisition transfer to SRM, I'm running manually the function  BBP_EPRTRANS_INSERT and then the BBP_EXTREQ_TRANSFER program. It show us that the Preq was correctly sent to SRM... but then, when we go to the SMQ1, I can

  • Operating system command in file adaptor

    Hi, I am doing file to Idoc scenario, can i use the Operating system command in file adaptor to compress the file at FTP server and decompress the file at IE. I don’t know is it possible and if yes then how or is there any other way to handle the big

  • Neuer PC. Wo sind die Alben (Adope Photoshop Elements 7)?

    Ich habe einen neuen PC (Windows 7 Professional) gekauft, dort wieder Photoshop Elements 7 installiert und die Fotos im Photoshop importiert. Nun fehlen mir aber die Alben, welche ich auf dem vorherigen PC im Photoshop definiert hatte. Wie kann ich d

  • Scanning through network printer

    Hi everyone, I know that this is actually not the right place to pose this question, but I couldn't figure out where to open this thread instead and I thought that it's more likely to get a useful hint in this forum. I want to scan pictures through a