JButton not showing

Hi all, I've tried really hard to figure this one out and am just not getting it.
All I want to do is add a JButton to a JPanel and then add that panel to the ContentPane of a JApplet. The button doesn't show though, unless I add it directly to the ContentPane.
I know this is really basic stuff and I've done it successfully many times in the past and now, even after reviewing code that works, I can't figure out why this doesn't.
Please help. :)
Thanks much.

Thanks, it didn't seem to work though. Below is the reduced code for testing:
JApplet:
public void init(){
setBounds(0,0,500,500);
panelControl=new WebCamControlPanel(this);
setContentPane(panelControl);
}//end init
JPanel:
public WebCamControlPanel(JApplet applet){
button=new JButton("Save");
add(button);
All the instance vars are declared as you'd expect and it compiles fine. I had to type this in instead on copy/paste so forgive any typos or trivial errors. I burnt out ;-)
Any help is welcome.
Thanks:)

Similar Messages

  • Images not showing in the jlabel/jbutton

    Hello all,
    I've a package in which my cards directory is located along with all my src files and compiled classes. All my images ****.gif files are inside this directory.
    Then I've following the icon object.
    protected static JLabel lblDeck;The following code is used to get the image.
      String imgPath;
         imgPath = isImageExists("imgBG1.gif");
              if (imgPath == "")
              {     // If the image of Card Deck(imgDeck) is not Found
                   lblDeck = new JLabel();
                   lblDeck.setBackground(new Color(0, 64, 128));
                   lblDeck.setOpaque(true);
                   flagImgDeckFound = false;
              } else {
                   // If the image of Card Deck is Found
                   imgDeck     = new ImageIcon(imgPath);
                   lblDeck = new JLabel(imgDeck);
    // Check if the image exists else return "";
      protected String isImageExists(String imgName) {
              java.net.URL imgURL = getClass().getResource("cards/" + imgName);
             if (imgURL != null)
             {     return (imgURL.toString());     }
             else
                  JOptionPane.showMessageDialog(null, "File not Found: " + imgURL);
                  return "";
         }I'm still unable to get the image in the jlabel!
    When i checked the path, it is exactly returning the path of the file.
    But its neither loading the image into the jlabel nor is it returning "".
    This is just the label part i've other jbuttons also. Even they are not displaying any images.

    aLkeshP wrote:
    can everyone see this thread?
    YES FER-CHRISE-SAKE.
    Just how many times do you intend posting the same identical question?
    images not showing in the jlabel/jbutton
    Problem in imageicon
    iconImage on JButton & JLabel
    Re: images not showing in the jlabel/jbutton

  • Image Buttons Not Showing Up

    Can someone help me out. My image buttons are not showing up until after I mouse over them. Any help or responses is appreciated.
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.util.Vector;
    import java.lang.Math;
    import javax.swing.*;
    public class PokerApp extends JApplet
    implements MouseListener, MouseMotionListener, ActionListener, ItemListener
    // -------------- Global Variables ------------------------
    int width, height;
    int mx, my; // the mouse coordinates
    Color bgc = Color.lightGray;
    Color fgc = Color.black;
    Checkbox players[] = new Checkbox[10];
    CheckboxGroup cbg;
    Image img;
    public void init() {
    width = getSize().width;
    height = getSize().height;
    setBackground(bgc);
    setForeground(fgc);
    String s1;
    boolean sel;
    JButton jb;
    Container contentPane = getContentPane();
    contentPane.setLayout(null);
    ImageIcon iic[] = new ImageIcon[13];
    cbg = new CheckboxGroup();
    for (int i=0; i<9; ++i) {
    s1 = Integer.toString(i+2);
    sel = (i == 7);
    players[i] = new Checkbox(s1, cbg, sel);
    players.setBackground(bgc);
    players[i].setForeground(fgc);
    players[i].setName(s1);
    // setBounds (x=hor, y=ver, wid, hgt)
    players[i].setBounds(80 + i*30, 5, 30, 20);
    contentPane.add(players[i]);
    players[i].addItemListener(this);
    for (int i=0; i<13; ++i) {
    img = getImage(getDocumentBase(), "images/v" + (i+1) + ".jpg");
    iic[i] = new ImageIcon(img);
    jb = new JButton(iic[i]);
    jb.addActionListener(this);
    jb.setBounds(i*30, 30, 30, 30);
    contentPane.add(jb);
    img = getImage(getDocumentBase(), "images/v2.jpg");
    ImageIcon tmp = new ImageIcon(img);
    jb = new JButton(tmp);
    jb.addActionListener(this);
    jb.setBounds(200, 200, 30, 30);
    jb.setVisible(true);
    contentPane.add(jb);
    jb.validate();
    addMouseListener( this );
    addMouseMotionListener( this );
    public void start() {
    // start or resume exectuion
    public void stop() {
    // suspends execution
    public void destroy() {
    // perform shutdown activites
    public void paint( Graphics g) {
    width = getSize().width;
    height = getSize().height;
    Font font1 = new Font("Ariel", Font.PLAIN, 11);
    g.setFont(font1);
    g.setColor( Color.red );
    g.drawRect(0, 0, (width - 1), 30);
    g.drawString( "Beginning", 5, 12);
    g.drawString( "# of Players", 5, 24);
    public void mouseEntered( MouseEvent me ) { }
    public void mouseExited( MouseEvent me ) { }
    public void mousePressed( MouseEvent me ) { }
    public void mouseReleased( MouseEvent me ) { }
    public void mouseClicked( MouseEvent me ) { }
    public void mouseDragged( MouseEvent e ) { }
    public void mouseMoved( MouseEvent e ) { }
    public void actionPerformed (ActionEvent ae) { }
    public void itemStateChanged(ItemEvent ie) { }

    The part you are missing is a call to super.paint in your paint method
        public void paint( Graphics g) {
            super.paint(g);
            ...This tells the component (the JApplet) to do its default rendering before it does the custom rendering in the paint method. So the component will render your buttons before it does the rest of the paint code.
    I also added an image loading method to your applet:
    //  <applet code="PA" width="400" height="400"></applet>
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.util.Vector;
    import java.lang.Math;
    import javax.swing.*;
    public class PA extends JApplet implements MouseListener, MouseMotionListener,
                                               ActionListener, ItemListener
        // -------------- Global Variables ------------------------
        int width, height;
        int mx, my;                             // the mouse coordinates
        Color bgc = Color.lightGray;
        Color fgc = Color.black;
        Checkbox players[] = new Checkbox[10];
        CheckboxGroup cbg;
    //    Image img;
        Font font1;
        public void init() {
            // only need to create a font one time, not with every paint call
            font1 = new Font("Ariel", Font.PLAIN, 11);
            width = getSize().width;
            height = getSize().height;
            setBackground(bgc);
            setForeground(fgc);
            String s1;
            boolean sel;
            JButton jb;
            Container contentPane = getContentPane();
            contentPane.setLayout(null);
    //        ImageIcon iic[] = new ImageIcon[13];
            cbg = new CheckboxGroup();
            for (int i=0; i<9; ++i) {
                s1 = Integer.toString(i+2);
                sel = (i == 7);
                players[i] = new Checkbox(s1, cbg, sel);
                players.setBackground(bgc);
    players[i].setForeground(fgc);
    players[i].setName(s1);
    // setBounds (x=hor, y=ver, wid, hgt)
    players[i].setBounds(80 + i*30, 5, 30, 20);
    contentPane.add(players[i]);
    players[i].addItemListener(this);
    Image[] images = loadImages();
    for(int j = 0; j < images.length; j++)
    ImageIcon icon = new ImageIcon(images[j]);
    JButton b = new JButton(icon);
    b.addActionListener(this);
    b.setBounds(j*30, 30, 30, 30);
    contentPane.add(b);
    Image image = getImage(getDocumentBase(), "images/v2.jpg");
    ImageIcon tmp = new ImageIcon(image);
    jb = new JButton(tmp);
    jb.addActionListener(this);
    jb.setBounds(200, 200, 30, 30);
    jb.setVisible(true);
    contentPane.add(jb);
    // jb.validate();
    addMouseListener( this );
    addMouseMotionListener( this );
    private Image[] loadImages()
    MediaTracker tracker = new MediaTracker(this);
    Image[] images = new Image[13];
    for (int j = 0; j < images.length; j++) {
    images[j] = getImage(getDocumentBase(), "images/v" + (j + 1) + ".jpg");
    tracker.addImage(images[j], 0);
    try
    tracker.waitForAll();
    catch(InterruptedException ie)
    System.err.println("tracker interrupt: " + ie.getMessage());
    return images;
    public void start() {
    // start or resume exectuion
    public void stop() {
    // suspends execution
    public void destroy() {
    // perform shutdown activites
    public void paint( Graphics g) {
    super.paint(g);
    width = getSize().width;
    height = getSize().height;
    g.setFont(font1);
    g.setColor( Color.red );
    g.drawRect(0, 0, (width - 1), 30);
    g.drawString( "Beginning", 5, 12);
    g.drawString( "# of Players", 5, 24);
    public void mouseEntered( MouseEvent me ) { }
    public void mouseExited( MouseEvent me ) { }
    public void mousePressed( MouseEvent me ) { }
    public void mouseReleased( MouseEvent me ) { }
    public void mouseClicked( MouseEvent me ) { }
    public void mouseDragged( MouseEvent e ) { }
    public void mouseMoved( MouseEvent e ) { }
    public void actionPerformed (ActionEvent ae) { }
    public void itemStateChanged(ItemEvent ie) { }

  • Gui labels and buttons not showing...

    I am using Java to create a gui and so far I have everything working.
    But there is a section of code thats not working out and Ill post the whole file here (not very big) to let you guys see whats going on. The issue lies in the action listner where I state "if a text feild is empty, display the option pane, else show the following" and its not showing the labels and buttons.
    Help?
    package student.information.search;
    import javax.swing.JFrame;
    import java.awt.GridBagLayout;
    import javax.swing.WindowConstants;
    import java.awt.Rectangle;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import java.awt.ActiveEvent;
    import java.awt.Frame;
    import java.awt.GridBagConstraints;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import student.information.readonly.ReadOnlyStudentForm;
    public class StudentSearch extends Frame implements ActionListener
       JTextField textField = new JTextField();
       JFrame frame = new JFrame();
       JPanel contentPane = (JPanel) frame.getContentPane();
       GridBagLayout gridBagLayout = new GridBagLayout();
        public StudentSearch()
            gridBagLayout.columnWidths = new int[]{20, 0, 12, 137, 17};
            gridBagLayout.rowHeights = new int[]{26, 0, 6, 0, 20};
            gridBagLayout.columnWeights = new double[]{1, 0, 0, 0, 0};
            gridBagLayout.rowWeights = new double[]{0, 0, 0, 0, 1};
            contentPane.setLayout(gridBagLayout);
            JButton button = new JButton();
            button.setText("Search");
            button.addActionListener(this);
            contentPane.add(button, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, 13, 0, new Insets(0, 0, 0, 0), 0, 0));
            textField.setColumns(8);
            contentPane.add(textField, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, 768, 2, new Insets(0, 0, 0, 0), 0, 0));
            JLabel label = new JLabel();
            label.setText("Student Seach");
            contentPane.add(label, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 256, 0, new Insets(0, 0, 0, 0), 0, 0));
            frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            frame.setTitle("Student Search");
            frame.setBounds(new Rectangle(500, 0, 500, 320));
            frame.setVisible(true);
       public void actionPerformed( ActionEvent arg0)
            if (textField.getText().equals(""))
              JOptionPane.showConfirmDialog(null, "Please enter a value in the search feild", "Error", JOptionPane.OK_CANCEL_OPTION); 
            else
               //Show the text fields here and the user information. 
                 *  While there are students for this search, change the text fields to Name, Last Name and ID and have a button called
                 *  View that when clicked allows for you to view all that students information.
                JLabel firstName = new JLabel();
                firstName.setText("Label");
                contentPane.add(firstName, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, 768, 0, new Insets(0, 0, 0, 0), 0, 0));
                JLabel lastName = new JLabel();
                lastName.setText("Label");
                contentPane.add(lastName, new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0, 256, 0, new Insets(0, 0, 0, 0), 0, 0));
                JLabel studentID = new JLabel();
                studentID.setText("Label");
                contentPane.add(studentID, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, 256, 0, new Insets(0, 0, 0, 0), 0, 0));
                JButton viewStudentInformation = new JButton();
                viewStudentInformation.setText("Search");
                viewStudentInformation.addActionListener(new ActionListener()
                        public void actionPerformed(ActionEvent e)
                               //For viewing individual student information
                                new ReadOnlyStudentForm();
                contentPane.add(viewStudentInformation, new GridBagConstraints(7, 3, 1, 1, 0.0, 0.0, 13, 0, new Insets(0, 0, 0, 0), 0, 0));
    }

    In general when adding or removing components for a visible GUI you need to use:
    panel.add(...);
    panel.revalidate();
    panel.repaint();

  • I add components to contentPane, but JFrame still does not show them

    I converted a small game I was making from AWT to Swing.(The game is just MineSweeper.) I made all the necessary adjustments like, Button to JButton and add() to getContentPane().add(), but when I show the JFrame, it does not show any components that I added. I have run test programs to see if I am adding the components correctly and they work.
    I print out the number of components contained in the frame by using getComponentCount() and the number is correct. It just will not show up in the JFrame. I have tried everything I can think of, no matter how strange and it still will not show the components.
    I have attached all the code to the bottom of this message. Can someone please take a look and see what I am missing.
    Thanks.
    Here's the code. The main file is at the end and is the one causing the problems. All the rest is just support stuff and should not be relavent, but I included it in case I missed something there.
    //Timer is just a custom timer
    import java.util.Date;
    public class Timer {
         Date curr;
         public Timer() {
              curr=new Date();
         public void start() {
              curr=new Date();
         public int getSeconds() {
              return (int)(((new Date().getTime())-curr.getTime())/1000);
    //Cover subclasses JButton for initial look
    import java.awt.*;
    import javax.swing.*;
    public class Cover extends JButton {
         Dimension size;
         public Cover() {
              super("");
              size=new Dimension(20,20);
              setSize(size);
         public Cover(String l) {
              super("");
              size=new Dimension(20,20);
              setSize(size);
         public void setSize(Dimension s) {
              super.setSize(size);
         public Dimension getPreferredSize() {
              return size.getSize();
         public Dimension getMinimumSize() {
              return size.getSize();
         public Dimension getMaximumSize() {
              return size.getSize();
    //Flag subclasses JButton to flag a mine
    import java.awt.*;
    import javax.swing.*;
    public class Flag extends JButton {
         Dimension size;
         public Flag() {
              super("F");
              size=new Dimension(20,20);
         public Flag(String l) {
              super("F");
              size=new Dimension(20,20);
         public void setSize(Dimension s) {
              super.setSize(size);
         public Dimension getPreferredSize() {
              return size.getSize();
         public Dimension getMinimumSize() {
              return size.getSize();
         public Dimension getMaximumSize() {
              return size.getSize();
    //Reveal subclasses JPanel to show what's underneath
    import java.awt.*;
    import javax.swing.*;
    public class Reveal extends JPanel {
         Dimension size;
         int number;
         Color color[];
         public Reveal(int n) {
              super();
              size=new Dimension(20,20);
              number=n;
              color=new Color[10];
              color[0]=Color.black;
              color[1]=Color.orange;
              color[2]=Color.cyan;
              color[3]=Color.yellow;
              color[4]=Color.green;
              color[5]=Color.magenta;
              color[6]=Color.blue;
              color[7]=Color.pink;
              color[8]=Color.darkGray;
              color[9]=Color.red;
              //for(int x=0;x<10;x++) {
              //     System.out.println(x+"="+color[x]);
              setBackground(Color.black);
         public void paintComponent(Graphics g) {
              int width=getWidth();
              int height=getHeight();
              FontMetrics fm=g.getFontMetrics();
              int fw=0;
              int fh=fm.getAscent();
              g.setColor(color[number]);
              if(number==9) {
                   fw=fm.stringWidth("M");
                   g.drawString("M",width/2-(fw/2),height/2+(fh/2));
              else if(number!=0) {
                   fw=fm.stringWidth(""+number);
                   g.drawString(""+number,width/2-(fw/2),height/2+(fh/2));
              g.setColor(Color.white);
              g.drawRect(1,1,width-2,height-2);
              //System.out.println("number="+number);
         public void setNumber(int n) {
              number=n;
         public int getNumber() {
              return number;
         public Dimension getPreferredSize() {
              return size.getSize();
         public Dimension getMinimumSize() {
              return size.getSize();
         public Dimension getMaximumSize() {
              return size.getSize();
    //MineSweeper just launches the program and subclasses JFrame
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MineSweeper extends JFrame implements ComponentListener {
         public MineSweeper(String s) {
              super(s);
              addComponentListener(this);
         public void quit() {
              System.exit(0);
         public void componentHidden(ComponentEvent e){}
         public void componentMoved(ComponentEvent e){}
         public void componentResized(ComponentEvent e){
              System.out.println("resized");
              MineSweeper temp=(MineSweeper)e.getSource();
              System.out.println("count="+temp.getContentPane().getComponentCount());
         public void componentShown(ComponentEvent e){}
         public static void main(String args[]) {
              MineSweeper t=new MineSweeper("Inside Moves");
              t.addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
              GameManager manager=new GameManager(t);
    //GameManager is the main program. This is where the JFrame is realized
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class GameManager implements MouseListener, ActionListener, Runnable {
         JPanel display;
         JPanel gameInfo;
         MineSweeper screen;
         JButton reset;
         JTextField tMine,time;
         Container pane;
         int clickX,clickY;
         int minesLeft;
         int gridX[],gridY[],mine[];
         static final int MAX_X=30;
         static final int MAX_Y=24;
         static final int MAX_MINE=667;
         JComponent grid[][];
         int board[][];
         int number[][];
         final static int OB=64;
         final static int BLANK=0;
         final static int MINE=1;
         final static int REVEAL=128;
         int level;
         final static int EASY=0;
         final static int MEDIUM=1;
         final static int HARD=2;
         final static int CUSTOM=3;
         int state;
         final static int START=1;
         final static int PLAYING=2;
         final static int DONE=3;
         Timer timer;
         int timeDisp;
         public GameManager(MineSweeper s) {
              screen=s;
              pane=screen.getContentPane();
              pane.setLayout(new BorderLayout());
              display=new JPanel();
              gameInfo=new JPanel(new GridLayout(1,3));
              reset=new JButton("Reset");
              tMine=new JTextField(20);
              time=new JTextField("0",20);
              grid=new JComponent[MAX_X+2][MAX_Y+2];
              board=new int[MAX_X+2][MAX_Y+2];
              number=new int[MAX_X+2][MAX_Y+2];
              gridX=new int[4];
              gridY=new int[4];
              mine=new int[4];
              level=EASY;
              gridX[0]=8;
              gridY[0]=8;
              mine[0]=10;
              gridX[1]=16;
              gridY[1]=16;
              mine[1]=40;
              gridX[2]=30;
              gridY[2]=16;
              mine[2]=99;
              gridX[3]=0;
              gridY[3]=0;
              mine[3]=0;
              minesLeft=mine[level];
              tMine.setText(""+minesLeft);
              state=START;
              timer=new Timer();
              reset.addActionListener(this);
              setup();
              Thread t=new Thread(this);
              t.start();
              /*System.out.println("count="+pane.getComponentCount());
              Component cc[]=pane.getComponents();
              for(int i=0;i<cc.length;i++) {
                   System.out.println("cc="+cc);
         public void setup() {
              boolean done;
              for(int x=0;x<=gridX[level]+1;x++) {
                   for(int y=0;y<=gridY[level]+1;y++) {
                        if(x==0 || x==gridX[level]+1 || y==0 || y==gridY[level]+1) {
                             board[x][y]=OB;
                             number[x][y]=-1;
                        else {
                             board[x][y]=BLANK;
              for(int i=0;i<mine[level];i++) {
                   done=false;
                   while(!done) {
                        int x=(int)((Math.random()*gridX[level])+1.0);
                        int y=(int)((Math.random()*gridY[level])+1.0);
                        if(board[x][y]==BLANK) {
                             board[x][y]=MINE;
                             done=true;
                             //System.out.println("Mine x="+x+" y="+y);
              for(int y=1;y<=gridY[level];y++) {
                   System.out.print("\n");
                   for(int x=1;x<=gridX[level];x++) {
                        number[x][y]=0;
                        if(board[x][y]==MINE) {
                             number[x][y]=9;
                             System.out.print(""+number[x][y]);
                             continue;
                        else {
                             //System.out.println("For board pos x="+x+" y="+y);
                             for(int i=-1;i<=1;i++) {
                                  for(int j=-1;j<=1;j++) {
                                       //System.out.print(""+board[x+i][y+j]);
                                       if(board[x+i][y+j]!=OB && board[x][y]==BLANK) {
                                            number[x][y]+=board[x+i][y+j];
                                  //System.out.print("\n");
                             System.out.print(""+number[x][y]);
              System.out.print("\n");
              screen.setVisible(false);
              display.removeAll();
              pane.removeAll();
              display.setLayout(new GridLayout(gridY[level],gridX[level]));
              for(int y=1;y<=gridY[level];y++) {
                   for(int x=1;x<=gridX[level];x++) {
                        Cover temp=new Cover();
                        //System.out.println("new button="+temp);
                        grid[x][y]=temp;
                        //System.out.println("display="+display.add(temp));
                        //display.add(temp);
                        temp.addMouseListener(this);
              //System.out.println("count="+display.getComponentCount());
              screen.setSize(gridX[level]*20,gridY[level]*20+30);
              pane.add(gameInfo,BorderLayout.NORTH);
              pane.add(display,BorderLayout.CENTER);
              minesLeft=mine[level];
              timeDisp=0;
              tMine.setText(""+minesLeft);
              time.setText(""+timeDisp);
              state=START;
              //System.out.println("gameInfo="+gameInfo);
              //System.out.println("display="+display);
              //screen.pack();
              screen.setVisible(true);
         void revealAround(int x,int y) {
              int index;
              Reveal tempRev=new Reveal(number[x][y]);
              grid[x][y]=tempRev;
              board[x][y]=(board[x][y]|REVEAL);
              index=(x-1)+((y-1)*gridX[level]);
              display.remove(index);
              display.add(tempRev,index);
              if(number[x][y]==0) {
                   for(int i=-1;i<=1;i++) {
                        for(int j=-1;j<=1;j++) {
                             if(!(i==0 && j==0)) {
                                  if((board[x+i][y+j]&REVEAL)!=REVEAL && board[x+i][y+j]!=OB) {
                                       revealAround(x+i,y+j);
         void startTimer() {
              timer.start();
         public void run() {
              while(true) {
                   if(state==PLAYING) {
                        if(timer.getSeconds()>timeDisp) {
                             timeDisp=timer.getSeconds();
                             time.setText(""+timeDisp);
                   else {
                        try {
                             Thread.sleep(1000);
                        catch (InterruptedException e) {
         public void actionPerformed(ActionEvent e) {
              if(e.getActionCommand().equals("Reset")) {
                   setup();
         public void mouseClicked(MouseEvent e) {
              if(state==START) {
                   startTimer();
                   state=PLAYING;
              if(state==PLAYING) {
                   Component tempComp=(Component)e.getSource();
                   boolean found=false;
                   int index=0;
                   int buttonPressed=e.getModifiers();
                   for(int x=1;x<=gridX[level];x++) {
                        if(found) {
                             break;
                        for(int y=1;y<=gridY[level];y++) {
                             if(tempComp==grid[x][y]) {
                                  clickX=x;
                                  clickY=y;
                                  found=true;
                                  break;
                   index=(clickX-1)+((clickY-1)*gridX[level]);
                   if(buttonPressed==InputEvent.BUTTON1_MASK && !(grid[clickX][clickY] instanceof Flag)) {
                        Reveal tempRev=new Reveal(number[clickX][clickY]);
                        grid[clickX][clickY]=tempRev;
                        board[clickX][clickY]=board[clickX][clickY]|REVEAL;
                        display.remove(index);
                        display.add(tempRev,index);
                   else if(buttonPressed==InputEvent.BUTTON3_MASK) {
                        if(display.getComponent(index) instanceof Cover) {
                             Flag tempFlag=new Flag();
                             grid[clickX][clickY]=tempFlag;
                             display.remove(index);
                             display.add(tempFlag,index);
                             tempFlag.addMouseListener(this);
                             minesLeft--;
                        else if(display.getComponent(index) instanceof Flag) {
                             Cover tempCov=new Cover();
                             grid[clickX][clickY]=tempCov;
                             display.remove(index);
                             display.add(tempCov,index);
                             tempCov.addMouseListener(this);
                             minesLeft++;
                        tMine.setText(""+minesLeft);
                   if(number[clickX][clickY]==0) {
                        revealAround(clickX,clickY);
                   screen.setVisible(true);
         public void mousePressed(MouseEvent e) {}
         public void mouseReleased(MouseEvent e) {}
         public void mouseEntered(MouseEvent e) {}
         public void mouseExited(MouseEvent e) {}

    setBounds() is only used for absolute positioning. I
    am using layout managers, so it should no be used.
    Thanks for you reply.Oh I get I did not look at your source code enought... can you post only the part that is bugy!?!?!
    JRG

  • The JPanel did not show when the menu is selected

    My program consists a JMenu bar with sub menu items. When the user select on the menu items a panel with the gridbag layout will show with all the labels.but the panel did not show. Can anyone show the problem for me ?
    AdminFrameMain.java
    public class AdminFrameMain
         private DisplayMenuBar menubar;
         private DisplayToolBar toolbar;
         private DisplayStatusBar statusbar;     
         public AdminFrameMain()
              JFrame frame = new JFrame("S-League Administration Management System");
              Toolkit kit = frame.getToolkit();
              Dimension windowsize =kit.getScreenSize();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              Container content = frame.getContentPane();
              content.setLayout(new BorderLayout());
              menubar = new DisplayMenuBar(frame,content);
              toolbar = new DisplayToolBar(content);
              statusbar = new DisplayStatusBar(content);
              frame.setSize(800,600);
              frame.setVisible(true);
         public static void main(String [] args){
              AdminFrameMain tm = new AdminFrameMain();
    DisplayMenuBar.java
    public class DisplayMenuBar
         private JMenu addMenu,addTeamMenu;
         private JMenuBar bar = new JMenuBar();
         private JToolBar toolbar = new JToolBar();
         private JMenuItem addTeamItem;
         private JFrame setFrame;
         private Container setContent;
         private AddTeamManagement addTeamMang;
         public DisplayMenuBar(JFrame frame,Container c)
              setFrame = frame;
              setContent = c;
              SetMenuBar();
         public void SetMenuBar()
         setFrame.setJMenuBar(bar);
         addMenu = new JMenu("Add");
         //file menu items list
         //Add sub menu
         addTeamMenu = new JMenu("Team Management");
         addMenu.add(addTeamMenu);
         //Add sub menu items
         addTeamMenu.add(addTeamItem = new JMenuItem("Add Team"));
         addTeamMenu.setMnemonic('T');     
         addTeamItem.setMnemonic('T');
         //team items listener
         //addTeamItem.addActionListener(taskcommand);          
         addTeamItem.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
                   AddTeamManagement addTeamMang = new AddTeamManagement(setFrame,setContent);
         bar.add(addMenu);
    AddTeamManagement.java
    public class AddTeamManagement
         private JPanel addTeamPanel;
         private JFrame frame;
         private JButton createTeamBt,resetTeamBt;
         private Container addTeamContent;
         private JTextArea teamDescTextArea,teamIndpTextArea;
         private JTextField teamNameField;
         private JLabel teamID,teamDesc,teamInfo,numOfPlayers,teamZone,playersNum;
         private GridBagLayout gridBag;
         private GridBagConstraints constraints;
         public AddTeamManagement(JFrame f,Container c)
              System.out.println("add team mg");
              addTeamPanel = new JPanel();
              frame = f;
              addTeamContent = c;
              gridBag = new GridBagLayout();
              addTeamPanel.setLayout(gridBag);
              addTeamPanel.setBackground(Color.pink);
              constraints = new GridBagConstraints();
              teamID = new JLabel("Team ID:");
              teamDesc = new JLabel("Team Description:");
              teamInfo = new JLabel("Team Info:");
              numOfPlayers = new JLabel("No Of Players:");
              playersNum = new JLabel("15 Maximun");
              teamZone = new JLabel("Team Zone:");
              constraints.fill = constraints.VERTICAL;
              constraints.weightx = 1;
              constraints.weighty = 0;
              addComponent(teamID,0,0,1,1);
              constraints.fill = constraints.VERTICAL;
              constraints.weightx = 1;
              constraints.weighty = 0;
              addComponent(teamDesc,1,0,1,1);
              constraints.fill = constraints.VERTICAL;
              constraints.weightx = 1;
              constraints.weighty = 0;
              addComponent(teamInfo,2,0,1,1);
              constraints.fill = constraints.VERTICAL;
              constraints.weightx = 1;
              constraints.weighty = 0;
              addComponent(numOfPlayers,3,0,1,1);
              constraints.fill = constraints.VERTICAL;
              constraints.weightx = 1;
              constraints.weighty = 0;
              addComponent(teamZone,4,0,1,1);
              System.out.println("showing");
              addTeamContent.add(addTeamPanel,BorderLayout.CENTER);
         public void addComponent(Component component,int row,int column,int width,int height)
              System.out.println("adding c");
              constraints.gridx = column;
              constraints.gridy = row;
              constraints.gridwidth = width;
              constraints.gridheight = height;
              gridBag.setConstraints(component,constraints);
              addTeamPanel.add(component);
              addTeamPanel.setVisible(true);
    }

    Hello,
    you are missing only one link, just add following line to your actionPerformed method of DisplayMenuBar class and all problem will be solved
    setContent.validate();
    Actually, Swing component does not updated automatically. when you do any changes to the component layout it will set that component as invalidated component. To update the view you need to call validate() method defined in JComponent class.
    Virus

  • In GlassPane Wait cusor is not showing ?

    Hello all,
    I want show wait cursor and disable all the mouse input outside the application.Please help.
    In my code , I am using glasspane object to do it, but it is not showing wait cusor and it is accepting mouse event outside the application.
    Please help.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TestGlass extends JFrame     implements ActionListener{
         private JButton closeButton;
         private Container c;
         MyGlassPane myGlassPane;
    //constructor -1
         public TestGlass()     {
              init();
              createGUI();
    //init
         void init()     {
              closeButton = new JButton("Close Me");
              c = getContentPane();
              myGlassPane = new MyGlassPane();
    //GUI
         void createGUI()     {
              setTitle("glass Pane Test");
              c.setLayout(new FlowLayout());
              c.add(closeButton);
              closeButton.addActionListener(this);
              addWindowListener     (     new WindowAdapter()     {
                                                 public void windowClosed(WindowEvent we)     {
                                                      closeApplication();
              //glass pane
              setGlassPane(myGlassPane);
              pack();
              setSize(400,300);
    //close
         void closeApplication()     {
              System.exit(0);
    //action handler
         public void actionPerformed(ActionEvent e)     {
              closeApplication();
    //main
         public static void main(String args[])     {
              new TestGlass().show();
    class MyGlassPane extends JComponent     {
         public MyGlassPane()     {
              //setSize(800,600);
              //setCursor(new Cursor(Cursor.WAIT_CURSOR));
              addMouseListener(     new MouseAdapter()     {
                                            public void mouseExited(MouseEvent me) {
                                                 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    Hi,
    in your subclass of JFrame you have to useCursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
    Component gp = getRootPane().getGlassPane();
    gp.setCursor(waitCursor);
    gp.setVisible(true); to get the glass pane.

  • Why the Image dose not show?

    the program can run, however, the image just dose not show on the container, I've mad ....
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    import javax.imageio.*;
    import java.io.*;
    public class gui extends JFrame{
    private stack s=new stack();
    private queue q1=new queue();
    private queue q2=new queue();
    private JRadioButton rbutton1,rbutton2,rbutton3,rbutton4,rbutton5;
    private JTextArea point1,point2,infoarea;
    private JButton ok ,exit;
    int state=0;
    private JLabel b=new JLabel(new ImageIcon("abc.jpg"));
    public gui() {    
    creatUserInterface();
    private void creatUserInterface(){
    Container contentPane=getContentPane();
    contentPane.setLayout(null);
    b.setBounds(0, 0,127,127);
    contentPane.add(b);
    rbutton1=new JRadioButton();
    rbutton1.setBounds(45, 270, 20,20);
    rbutton1.setBackground(Color.decode("170800"));
    contentPane.add(rbutton1);
    rbutton2=new JRadioButton();
    rbutton2.setBounds(145, 270, 20,20);
    rbutton2.setBackground(Color.decode("170800"));
    contentPane.add(rbutton2);
    rbutton3=new JRadioButton();
    rbutton3.setBounds(245, 270, 20,20);
    rbutton3.setBackground(Color.decode("170800"));
    contentPane.add(rbutton3);
    rbutton4=new JRadioButton();
    rbutton4.setBounds(345, 270, 20,20);
    rbutton4.setBackground(Color.decode("170800"));
    contentPane.add(rbutton4);
    rbutton5=new JRadioButton();
    rbutton5.setBounds(445, 270, 20,20);
    rbutton5.setBackground(Color.decode("170800"));
    contentPane.add(rbutton5);
    point1=new JTextArea();
    point1.setBounds(585, 20, 43, 20);
    contentPane.add(point1);
    point2=new JTextArea();
    point2.setBounds(585, 205, 43, 20);
    contentPane.add(point2);
    infoarea=new JTextArea();
    infoarea.setBounds(30, 300, 450, 100);
    infoarea.setText("click \"ok \" to start game, click \"exit \" to exit");
    contentPane.add(infoarea);
    ok=new JButton();
    ok.setBounds(520, 255, 75, 60);
    ok.setText("OK");
    contentPane.add(ok);
    ok.addActionListener(
    new ActionListener(){
    public void actionPerformed(ActionEvent event){          
    okButton(event);
    exit=new JButton();
    exit.setBounds(520, 340, 75, 65);
    exit.setText("EXIT");
    contentPane.add(exit);
    exit.addActionListener(
    new ActionListener(){
    public void actionPerformed(ActionEvent event){          
    exitButton(event);
    contentPane.setBackground(Color.decode("170800"));
    setTitle("Change it or Not");
    setSize(640, 480);
    setVisible(true);
    Message was edited by:
    explosivealan

    because the code is very long and i just cut the code i think is not related, i post all the code here, should i post the code of stack , queue and others class?My objective is to show all cardLabel as jpg, abc is to test only.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    import javax.imageio.*;
    import java.io.*;
    public class gui extends JFrame{
        private stack s=new stack();                                      // a stack with 52 node to store 52 cards
        private queue q1=new queue();                                     // a queue to hold the computer player's cards
        private queue q2=new queue();                                     // a queue to hold the human player's cards
        private cardoperation op=new cardoperation();                    // contain all card operation that require to run the game       
        private handcompare hc=new handcompare();                        // pass two queue to handcompare, if the first queue defealt the second queue, return true, otherwise reture false
        private JLabel cardlabel1,cardlabel2,cardlabel3,cardlabel4,cardlabel5,cardlabel6,cardlabel7,cardlabel8,cardlabel9,cardlabel10;     // label to show the cards
        private JLabel computerpoint,playerpoint,inputbet,dollarsign;        
        private JRadioButton rbutton1,rbutton2,rbutton3,rbutton4,rbutton5;   //radio button for selecting which card to be changed
        private JTextField bet;                                               //Textfield to input the amount of bet
        private JTextArea point1,point2,infoarea;                             //textarea to show player's point and futher infomation;
        private JButton ok ,exit;                                             //button to confirm or to exit game
        int compoint=10000,playpoint=10000;                                    // integer to store the player's current point;'
        int betamount;                                                         // integer to store the current bet amount
        int state=0;                                                           // store the state of the program
        private JLabel b=new JLabel(new ImageIcon("abc.jpg"));
        public gui() {    
            super();
            creatUserInterface();
        private void creatUserInterface(){
        Container contentPane=getContentPane();   
        contentPane.setLayout(null);
        cardlabel1=new JLabel();
        cardlabel1.setBounds(50, 15, 50, 30);
        cardlabel1.setText("");
        contentPane.add(cardlabel1);
        b.setBounds(0, 0,127,127);
        contentPane.add(b);
        cardlabel2=new JLabel();
        cardlabel2.setBounds(150, 15, 50, 30);
        cardlabel2.setText("");
        contentPane.add(cardlabel2);
        cardlabel3=new JLabel();
        cardlabel3.setBounds(250, 15, 50, 30);
        cardlabel3.setText("");
        contentPane.add(cardlabel3);
        cardlabel4=new JLabel();
        cardlabel4.setBounds(350, 15, 50, 30);
        cardlabel4.setText("");
        contentPane.add(cardlabel4);
        cardlabel5=new JLabel();
        cardlabel5.setBounds(450, 15, 50, 30);
        cardlabel5.setText("");
        contentPane.add(cardlabel5);
        cardlabel6=new JLabel();
        cardlabel6.setBounds(50, 200, 50, 30);
        cardlabel6.setText("");
        contentPane.add(cardlabel6);
        cardlabel7=new JLabel();
        cardlabel7.setBounds(150, 200, 50, 30);
        cardlabel7.setText("");
        contentPane.add(cardlabel7);
        cardlabel8=new JLabel();
        cardlabel8.setBounds(250, 200, 50, 30);
        cardlabel8.setText("");
        contentPane.add(cardlabel8);
        cardlabel9=new JLabel();
        cardlabel9.setBounds(350, 200, 50, 30);
        cardlabel9.setText("");
        contentPane.add(cardlabel9);
        cardlabel10=new JLabel();
        cardlabel10.setBounds(450, 200, 50, 30);
        cardlabel10.setText("");
        contentPane.add(cardlabel10);
        rbutton1=new JRadioButton();
        rbutton1.setBounds(45, 270, 20,20);
        rbutton1.setBackground(Color.decode("170800"));
        contentPane.add(rbutton1);
        rbutton2=new JRadioButton();
        rbutton2.setBounds(145, 270, 20,20);
        rbutton2.setBackground(Color.decode("170800"));
        contentPane.add(rbutton2);
        rbutton3=new JRadioButton();
        rbutton3.setBounds(245, 270, 20,20);
        rbutton3.setBackground(Color.decode("170800"));
        contentPane.add(rbutton3);
        rbutton4=new JRadioButton();
        rbutton4.setBounds(345, 270, 20,20);
        rbutton4.setBackground(Color.decode("170800"));
        contentPane.add(rbutton4);
        rbutton5=new JRadioButton();
        rbutton5.setBounds(445, 270, 20,20);
        rbutton5.setBackground(Color.decode("170800"));
        contentPane.add(rbutton5);
        computerpoint=new JLabel();
        computerpoint.setBounds(500, 15, 80, 30);
        computerpoint.setText("computer has");
        contentPane.add(computerpoint);
        playerpoint=new JLabel();
        playerpoint.setBounds(500, 200, 80, 30);
        playerpoint.setText("you have");
        contentPane.add(playerpoint);
        inputbet=new JLabel();
        inputbet.setBounds(500, 90, 130, 20);
        inputbet.setText("please input bet here");
        contentPane.add(inputbet);   
        dollarsign=new JLabel();
        dollarsign.setBounds(510, 115, 20, 20);
        dollarsign.setText("$");
        contentPane.add(dollarsign);   
        point1=new JTextArea();
        point1.setBounds(585, 20, 43, 20);   
        contentPane.add(point1);  
        point2=new JTextArea();
        point2.setBounds(585, 205, 43, 20);
        contentPane.add(point2);  
        infoarea=new JTextArea();
        infoarea.setBounds(30, 300, 450, 100);
        infoarea.setText("click \"ok \" to start game, click \"exit \" to exit");
        contentPane.add(infoarea);
        bet=new JTextField();
        bet.setBounds(530, 115, 60, 20);
        contentPane.add(bet);  
        ok=new JButton();
        ok.setBounds(520, 255, 75, 60);
        ok.setText("OK");
        contentPane.add(ok);
        ok.addActionListener(
                    new ActionListener(){
               public void actionPerformed(ActionEvent event){          
                 okButton(event);
        exit=new JButton();
        exit.setBounds(520, 340, 75, 65);
        exit.setText("EXIT");
        contentPane.add(exit);
        exit.addActionListener(
                    new ActionListener(){
               public void actionPerformed(ActionEvent event){          
                 exitButton(event);
        contentPane.setBackground(Color.decode("170800"));
        setTitle("Change it or Not");
        setSize(640, 480);
        setVisible(true);
        private void displayLabel(){
            int a[]=new int[5];
            int b[]=new int[5];
            String a1[]=new String[5];
            String b1[]=new String[5];
            a=q1.copy_queue();
            b=q2.copy_queue();
            int i;
                for(i=0;i<5;i++){
            if(a%100==13) a1[i]="A";
    else if(a[i]%100>0&&a[i]%100<10)a1[i]=String.valueOf(a[i]%100+1);
    else if(a[i]%100==10)a1[i]="J";
    else if(a[i]%100==11)a1[i]="Q";
    else if(a[i]%100==12)a1[i]="K";
    for(i=0;i<5;i++){
    if(b[i]%100==13) b1[i]="A";
    else if(b[i]%100>0&&b[i]%100<10)b1[i]=String.valueOf(b[i]%100+1);
    else if(b[i]%100==10)b1[i]="J";
    else if(b[i]%100==11)b1[i]="Q";
    else if(b[i]%100==12)b1[i]="K";
    cardlabel1.setText(a1[0]);
    if(a[0]/100==4)
    cardlabel1.setForeground(Color.PINK);
    else if(a[0]/100==3)
    cardlabel1.setForeground(Color.BLUE);
    else if(a[0]/100==2)
    cardlabel1.setForeground(Color.RED);
    else if(a[0]/100==1)
    cardlabel1.setForeground(Color.BLACK);
    cardlabel2.setText(a1[1]);
    if(a[1]/100==4)
    cardlabel2.setForeground(Color.PINK);
    else if(a[1]/100==3)
    cardlabel2.setForeground(Color.BLUE);
    else if(a[1]/100==2)
    cardlabel2.setForeground(Color.RED);
    else if(a[1]/100==1)
    cardlabel2.setForeground(Color.BLACK);
    cardlabel3.setText(a1[2]);
    if(a[2]/100==4)
    cardlabel3.setForeground(Color.PINK);
    else if(a[2]/100==3)
    cardlabel3.setForeground(Color.BLUE);
    else if(a[2]/100==2)
    cardlabel3.setForeground(Color.RED);
    else if(a[2]/100==1)
    cardlabel3.setForeground(Color.BLACK);
    cardlabel4.setText(a1[3]);
    if(a[3]/100==4)
    cardlabel4.setForeground(Color.PINK);
    else if(a[3]/100==3)
    cardlabel4.setForeground(Color.BLUE);
    else if(a[3]/100==2)
    cardlabel4.setForeground(Color.RED);
    else if(a[3]/100==1)
    cardlabel4.setForeground(Color.BLACK);
    cardlabel5.setText(a1[4]);
    if(a[4]/100==4)
    cardlabel5.setForeground(Color.PINK);
    else if(a[4]/100==3)
    cardlabel5.setForeground(Color.BLUE);
    else if(a[4]/100==2)
    cardlabel5.setForeground(Color.RED);
    else if(a[4]/100==1)
    cardlabel5.setForeground(Color.BLACK);
    cardlabel6.setText(b1[0]);
    if(b[0]/100==4)
    cardlabel6.setForeground(Color.PINK);
    else if(b[0]/100==3)
    cardlabel6.setForeground(Color.BLUE);
    else if(b[0]/100==2)
    cardlabel6.setForeground(Color.RED);
    else if(b[0]/100==1)
    cardlabel6.setForeground(Color.BLACK);
    cardlabel7.setText(b1[1]);
    if(b[1]/100==4)
    cardlabel7.setForeground(Color.PINK);
    else if(b[1]/100==3)
    cardlabel7.setForeground(Color.BLUE);
    else if(b[1]/100==2)
    cardlabel7.setForeground(Color.RED);
    else if(b[1]/100==1)
    cardlabel7.setForeground(Color.BLACK);
    cardlabel8.setText(b1[2]);
    if(b[2]/100==4)
    cardlabel8.setForeground(Color.PINK);
    else if(b[2]/100==3)
    cardlabel8.setForeground(Color.BLUE);
    else if(b[2]/100==2)
    cardlabel8.setForeground(Color.RED);
    else if(b[2]/100==1)
    cardlabel8.setForeground(Color.BLACK);
    cardlabel9.setText(b1[3]);
    if(b[3]/100==4)
    cardlabel9.setForeground(Color.PINK);
    else if(b[3]/100==3)
    cardlabel9.setForeground(Color.BLUE);
    else if(b[3]/100==2)
    cardlabel9.setForeground(Color.RED);
    else if(b[3]/100==1)
    cardlabel9.setForeground(Color.BLACK);
    cardlabel10.setText(b1[4]);
    if(b[4]/100==4)
    cardlabel10.setForeground(Color.PINK);
    else if(b[4]/100==3)
    cardlabel10.setForeground(Color.BLUE);
    else if(b[4]/100==2)
    cardlabel10.setForeground(Color.RED);
    else if(b[4]/100==1)
    cardlabel10.setForeground(Color.BLACK);
    point1.setText("$"+String.valueOf(compoint)); //show the value back if player has change it accdentially
    point2.setText("$"+String.valueOf(playpoint));
    if(betamount==0)
    bet.setText("");
    else
    bet.setText(String.valueOf(betamount));
    private void displayHalf(){
    int b[]=new int[5];
    String b1[]=new String[5];
    b=q2.copy_queue();
    int i;
    for(i=0;i<5;i++){
    if(b[i]%100==13) b1[i]="A";
    else if(b[i]%100>0&&b[i]%100<10)b1[i]=String.valueOf(b[i]%100+1);
    else if(b[i]%100==10)b1[i]="J";
    else if(b[i]%100==11)b1[i]="Q";
    else if(b[i]%100==12)b1[i]="K";
    cardlabel6.setText(b1[0]);
    if(b[0]/100==4)
    cardlabel6.setForeground(Color.PINK);
    else if(b[0]/100==3)
    cardlabel6.setForeground(Color.BLUE);
    else if(b[0]/100==2)
    cardlabel6.setForeground(Color.RED);
    else if(b[0]/100==1)
    cardlabel6.setForeground(Color.BLACK);
    cardlabel7.setText(b1[1]);
    if(b[1]/100==4)
    cardlabel7.setForeground(Color.PINK);
    else if(b[1]/100==3)
    cardlabel7.setForeground(Color.BLUE);
    else if(b[1]/100==2)
    cardlabel7.setForeground(Color.RED);
    else if(b[1]/100==1)
    cardlabel7.setForeground(Color.BLACK);
    cardlabel8.setText(b1[2]);
    if(b[2]/100==4)
    cardlabel8.setForeground(Color.PINK);
    else if(b[2]/100==3)
    cardlabel8.setForeground(Color.BLUE);
    else if(b[2]/100==2)
    cardlabel8.setForeground(Color.RED);
    else if(b[2]/100==1)
    cardlabel8.setForeground(Color.BLACK);
    cardlabel9.setText(b1[3]);
    if(b[3]/100==4)
    cardlabel9.setForeground(Color.PINK);
    else if(b[3]/100==3)
    cardlabel9.setForeground(Color.BLUE);
    else if(b[3]/100==2)
    cardlabel9.setForeground(Color.RED);
    else if(b[3]/100==1)
    cardlabel9.setForeground(Color.BLACK);
    cardlabel10.setText(b1[4]);
    if(b[4]/100==4)
    cardlabel10.setForeground(Color.PINK);
    else if(b[4]/100==3)
    cardlabel10.setForeground(Color.BLUE);
    else if(b[4]/100==2)
    cardlabel10.setForeground(Color.RED);
    else if(b[4]/100==1)
    cardlabel10.setForeground(Color.BLACK);
    cardlabel1.setText("");
    cardlabel2.setText("");
    cardlabel3.setText("");
    cardlabel4.setText("");
    cardlabel5.setText("");
    point1.setText("$"+String.valueOf(compoint)); //show the value back if player has change it accdentially
    point2.setText("$"+String.valueOf(playpoint));
    if(betamount==0)
    bet.setText("");
    else
    bet.setText(String.valueOf(betamount));
    private void okButton(ActionEvent event){
    switch(state){
    case(0):{
    op.reshuffle(s);
    op.CardDistribe(s, q1, q2);
    displayHalf();
    infoarea.setText("please input your bet and click \"ok \" \n\nSpace is Black Heart is Red \nClub is Bleu Diamond is Pink");
    break;
    case(1):{  
    try{
    betamount=Integer.parseInt(bet.getText());
    catch(NumberFormatException e){
    infoarea.setText("invaild input, please try again");
    state=state-1;
    if(state==1)
    if(betamount<=0||betamount>playpoint)
    {infoarea.setText("please input between 1 & "+String.valueOf(playpoint));
                           state=state-1;}
    else
    {infoarea.setText("please choose the cards to be changed \n\nSpace is Black    Heart is Red \nClub is Bleu         Diamond is Pink"); 
                           displayLabel();}
    break;
    case(2):{           
    infoarea.setText("choosed card has been changed");
    int a[]=new int[5];
    for(int i=0;i<5;i++)
    a[i]=0;
    if(rbutton1.isSelected())
    a[0]=1;
    if(rbutton2.isSelected())
    a[1]=1;
    if(rbutton3.isSelected())
    a[2]=1;
    if(rbutton4.isSelected())
    a[3]=1;
    if(rbutton5.isSelected())
    a[4]=1;
    op.computerChangeCard(s, q1, hc);
    op.playerChangeCard(s, q2, a);
    displayLabel();
    break;
    case(3):{          
    if(hc.compare(q1, q2)){
    infoarea.setText("you loss\n\nclick \"ok \" to continue");
    playpoint=playpoint-betamount;
    compoint=compoint+betamount;
    else{
    infoarea.setText("you win\n\nclick \"ok \" to continue");
    playpoint=playpoint+betamount;
    compoint=compoint-betamount;
    betamount=0;
    displayLabel();
    if(playpoint<=0)
    infoarea.setText("you have loss the game, press \"ok \" or \"exit \" to end game");
    else if(compoint<=0)
    infoarea.setText("you have win the game, press \"ok \" or \"exit \" to end game");
    else{
    state=-1;
    break;
    case(4):{
    exit(); // player's point <=0, so force to exit'
    default:
    rbutton1.setSelected(false);
    rbutton2.setSelected(false);
    rbutton3.setSelected(false);
    rbutton4.setSelected(false);
    rbutton5.setSelected(false);
    state=state+1;
    private void exitButton(ActionEvent event){
    exit();
    private void exit(){
    System.exit(0);

  • ITunes does not show up on apple tv 1st gen.

    i have a 1st gen apple tv with the 160 gig HD. recently, it will not show the itunes site. Under teh movies tab there are my movies and trailers and that's it. Does anyone know how to get the itunes store back on apple tv?

    Known issue currently, you'll need to wait for the fix.

  • My downloaded text sounds do not show up under the sounds tab in settings after installing 8.1.1. can someone help me please?

    i downloaded a couple text tones and since installing 8.1.1, they will not show up under the sounds tab. in fact, they do not show up in my recent purchases on itunes, but when i go to buy them again, it says that i have already bought this tone. I just want to use the tones i paid for as the tones on my phone. not asking much.... thanks for the help. i hope someone can help me get the tones working. thank you.

    This was happening to me too but only for some of my songs. I have a mac so I dunno about PCs, but for most of my ringtones I had to create an ACC version in itunes to make them short enough then turn that into a m4r and those all worked fine. But if the song was already short enough and I didn't create an ACC version and just turned the original into a m4r, then it wouldn't appear in my itunes.
    so if you're on a mac:
    1. go to get info, options, pick when you want the song to start and end.
         Has to be pretty short to work, 30 second or less is good
         if it's already short enough that's fine
    2. right click and click 'create ACC version'
         a copy with the length you put in will appear, drag that into a folder or whatever and just type in m4r where m4a would be
         still make an ACC version even if it's the right length
    Hopefully this helps someone else.

  • Internet Streams in Playlists do not show up on Apple TV

    I use the following setup:
    - Apple TV MD199LL/A (Software 6.0.1) just updated to the latest
    - iTunes 11.1.3 for Windows (from a Windows 7 x64)
    - iTunes 11.1.3 for MAC (from a Apple MacBook Pro x64, Maverix)
    Homesharing is turned on both computers
    From both machines I share pictures, videos and music.
    All photos, videos and music files are getting displayed  on the Apple TV menu, and can be played.
    All iTunes playlists from both machines are  getting displazed on the Apple TV
    BUT!
    If a internet stream is added to a playlist, this entry does not show on the Apple TV menu.
    If the playlist contains only internet streams the Apple TV menu says "There are no songs in this library"
    If I hit the play key on my remote, it  will randomly play the first stream in the playlist (not realy reproducable pattern)
    I can play those streams in iTunes and send it via AirPlay without problems,
    Can anyone help me with this and tell me what I'm doing wrong?
    Thank you

    You can only view that rental on the iPad. For it to show up it has to be rented directly on ATV or through a computer and streamed via home sharing

  • When I sync my iPod to my MacBook through iTunes new events do not show up and old events are not deleted. I am using Snow Leopard  and not iSync.

    I am using Snow Leopard on a MacBook. I have an iPod touch 3G. I do not use iSync it Mobile Me. When I sync my iPod through iTunes new events on my iPod do not show up on my Mac and old events do not delete. I have read help instructions that include deleting the data on the iPod. The iPod has the correct data and the Mac does not so I have not followed those instructions. I need help as the only reason I bought the Mac was to be able to sync, back up, view and print my calendar. Currently it is useless. If only Apple could have learned from the elegance of the Palm software.

    Start here:
    iPhone, iPad, or iPod touch: Device not recognized in iTunes for Windows

  • Synced videos do not show up on iPod

    Every time I sync my iPod with iTunes, although iTunes says the videos are synced, they do not show up in the Video app on the iPod.
    This is a fairly new problem.  All these videos have been synced before and they all showed up just fine in the Video app, but as of late the iPod does not show them.  Searching for them yields no results.
    The videos are in a compatible format and do not have an extremely high definition.  Again, I do not think the problem is with the videos, because previously I was able to view them all just fine.
    I have at least 1G of memory left, 2G without syncing the videos.
    I have erased and re-synced them in iTunes, to no avail.  I can play the videos on the iPod from iTunes, but not on the actual iPod device.  I'm using windows iTunes, and it is up to date.  The iPod software is up to date.  I don't want to do a restore because I've already done that multiple times for multiple issues, but if that's what I have to do, I will. It's a pretty old iPod.  I'm syncing with a third-party Duracell cable, but I really don't think that's the problem.
    I'm not sure what it means, but in iTunes I have checked the option that reads, "Prefer standard definition videos".  Syncing with that option unchecked changes nothing so far as I can tell.
    Thanks for all your help!
    iPod Touch 4th Gen. 8G
    iOS 6.1.6
    1G free with videos, 2G free without
    iTunes for Windows 64-bit V12.1
    Duracell 30 pin to USB iPod cable

    Try:
    - DFU mode and then restore to factory settings/new iPod via iTunes                   
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - Removing and reinstalling iTunes and other software components for Windows Vista, Windows 7, or Windows 8
    - Try with a new video

  • Files do not show up on HDD

    I tried to get an answer through the iTunes community, and was advised to try here instead as it didn't have anything directly to do with iTunes
    Not all iTunes Files not showing up on External HDD
    So in a nutshell, all of my 35'000 iTunes files (actual MP3 files) were saved on a TC 2.0TB disk and used on multiple Mac's to pull music from. All music files would be saved and streamed wirelessly from this TC and nowhere else.
    I would always add files to this external wireless client and iTunes would work flawlessly playing whatever song I chose through the library.
    If I would go in to the iTunes directory (path) and look up files on the HDD the files were just not there (but if clicking on the link through iTunes - show in finder - they would appear on the HDD but only through this method). I gave it no further thought until my TC died (i.e. no longer powers up) on me...
    I removed the HDD from the TC and placed it in an USB cradle and after looking into the iTunes folder there are only a fraction of the folders / files much less than expected... When I do a cmd-I I'm told that there are 35'000 files, but they just won't show up.
    Any ideas on how i can get all the files to be displayed as I want to copy these over on a new TC and need to map iTunes to this new location/path?

    Hello Jfrosa,
    Thank you for the details of the issue you are experiencing with File Sharing.  I found an article that should help with troubleshooting this:
    OS X: How to connect to Windows File Sharing (SMB) using Snow Leopard or earlier
    http://support.apple.com/kb/ht1568
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Movie rentals that I downloaded onto iMac with Lion to do not show up on ATV 2 in menu for computers.  Purchased movies show up just fine.  What to do or look for?

    I have an imac that is running lion and an Apple TV generation 2.  I have rented a movie from itunes and it shows up on my imac in Itunes under a rental icon, and will play fine on my computer.  However, it does not show up as choice to play on my apple tv.  I have homesharing enabled and everything else works fine including purchased movies that are on my imac, but no where does it show rental movies. 
    What do I look for?  What do I do to play the rental movie on my apple tv 2?

    Answer to my own question:
    Wait until the downloaded rental has completed its download to the imac.  This took a long time for me, since it was part of several things that I was downloading at the same time.
    Finally, it showed up on my apple tv.   Interestingly, I was able to watch much of the movie on my iMac before the movie finished its download and was available to the ATV 2.

Maybe you are looking for