Trouble Getting Any Display of JFrame Components

Hello all! I appreciate being able to post questions on this forum, and am grateful for anyone's help with this.
I have written a program that displays a GUI and (will) read a random word from a file for use in a Hangman-like game.
The trouble is, today I have no display (yesterday I had display just fine!). When I run the program, it opens just an empty Container with nothing inside.
Am I crazy, but does my code create valid content for a display?
Also, I use NetBeans 6.1.
Would anyone know why one day I would get good display and the next nothing?
Any advice or suggestions for my code are greatly appreciated! Thanks!
package secretphraseusingfile;
import java.io.*;       //program uses IOStreams
import java.awt.*;      //program uses Font, Colors
import java.awt.geom.*; //program uses shapes
import java.awt.event.*;//program uses ActionListeners
import javax.swing.*;   //program uses JOptionPane, JFrame
//Class SecretPhraseUsingFile
class DrawPanel extends JPanel
        int type = 1;
        public DrawPanel(int type)
            this.type = type;
    @Override
        protected void paintComponent(Graphics gr)
            super.paintComponent(gr);
            Color gallowColor = new Color(100, 100, 15);
            Graphics2D gr2D = (Graphics2D)gr;
            gr2D.setColor(gallowColor);
            gr2D.draw(new Rectangle2D.Float(100F, 50F, 400F, 333F));
            gr2D.fillRect(210, 60, 20, 300);
            gr2D.fillRect(230, 60, 120, 20);
            gr2D.fillRect(320, 80, 4,   50);
        }//end paintComponent
    }//end DrawPanel
public class SecretPhraseUsingFile extends JFrame
                                   implements ActionListener
    DataInputStream istream;
    //declaration of program-wide variables
    String letter = "";
    String filePath = "C:\\Users\\Ben\\Desktop\\Lesson 13\\Hangman";
    String fileName = "secretList.dat";
    File wordFile = new File(filePath, fileName);
    //declaration of JFrame components
    //layouts
    GridLayout masterGrid       = new GridLayout(2, 1);
    GridLayout topGrid          = new GridLayout(1, 2);
    GridLayout bottomGrid       = new GridLayout(3, 1);
    GridLayout innerButtonsGrid = new GridLayout(6, 5, 15, 2);
    FlowLayout innerFlow        = new FlowLayout();
    //panels
    JPanel masterP  = new JPanel(masterGrid);
    JPanel topP     = new JPanel(topGrid);
    DrawPanel drawingP = new DrawPanel(1);
    JPanel usedP    = new JPanel(innerFlow);
    JPanel bottomP  = new JPanel(bottomGrid);
    JPanel wordP    = new JPanel(innerFlow);
    JPanel buttonP  = new JPanel(innerButtonsGrid);
    JPanel captionP = new JPanel(innerFlow);
    Container con   = new Container();
    //fonts
    Font buttonsFont        = new Font("Arial Black", Font.BOLD, 16);
    Font usedFont           = new Font("Courier New", Font.BOLD, 54);
    Font usedTitleFont      = new Font("Courier New", Font.BOLD, 34);
    Font wordFont           = new Font("Arial Black", Font.BOLD, 84);
    Font captionFont        = new Font("Helvetica",   Font.BOLD, 30);
    Font captionExtremeFont = new Font("Helvetica",   Font.BOLD, 36);
    //colors
    Color backgroundColor = new Color(100, 180, 230);
    Color buttonColor     = new Color(70, 170, 150);
    Color gallowColor     = new Color(100, 100, 15);
    //labels
    JLabel caption          = new JLabel("Uh oh!");
    JLabel usedL[]          = new JLabel[26];
    JLabel lblLettersUsed   = new JLabel("Letters You've Used So Far: ");
    JLabel wordLabel        = new JLabel("_ _ _ _ _ _ _ _ _");
    //buttons
    JButton abc[]       = new JButton[26];
    JButton exitButton  = new JButton("EXIT");
    //JFrame constructor//////////////////////////////////////
    public SecretPhraseUsingFile()
        super("Hangman Game Using File");
        //create alphabet buttons
        for(int i = 0; i < 26; i++)
            letter = Character.toString((char)(i + 65));
            abc[i] = new JButton(letter);
            abc.setFont(buttonsFont);
abc[i].setBackground(buttonColor);
abc[i].setBorder(BorderFactory.createLineBorder(Color.BLACK));
//create used letter array for display of used letters
for(int i = 0; i < 26; i++)
letter = Character.toString((char)(i + 65));
usedL[i] = new JLabel(" " + letter + " ");
//keeps used letters invisible until chosen in game
usedL[i].setVisible(false);
usedL[i].setFont(usedFont);
usedL[i].setForeground(Color.RED);
drawingP.setBackground(backgroundColor);
usedP.setBackground(backgroundColor);
wordP.setBackground(backgroundColor);
buttonP.setBackground(backgroundColor);
captionP.setBackground(backgroundColor);
caption.setFont(captionFont);
con.add(masterP);
masterP.add(topP);
masterP.add(bottomP);
topP.add(drawingP);
topP.add(usedP);
bottomP.add(wordP);
bottomP.add(buttonP);
bottomP.add(captionP);
captionP.add(caption);
wordP.add(wordLabel);
wordLabel.setFont(wordFont);
for(int i = 0; i < 26; i++)
buttonP.add(abc[i]);
abc[i].addActionListener(this);
usedP.add(lblLettersUsed);
lblLettersUsed.setFont(usedTitleFont);
for(int i = 0; i < 26; i++)
usedP.add(usedL[i]);
buttonP.add(exitButton);
exitButton.addActionListener(this);
//create file opening for read from file
try
istream = new DataInputStream(new FileInputStream(wordFile));
catch(IOException ioe)
System.err.println("File not opened. " + "Cause: " + ioe.getMessage());
}//end of constructor
//main method runs java program
public static void main(String[] args) {
//declaration of constants
int DELTA_X = 0, DELTA_Y = 0;
int FRAME_WIDTH = 1280, FRAME_HEIGHT = 770;
//declaration of JFrame
SecretPhraseUsingFile display = new SecretPhraseUsingFile();
display.setBounds(DELTA_X, DELTA_Y, FRAME_WIDTH, FRAME_HEIGHT);
display.setVisible(true);
display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//end of method main
public void actionPerformed(ActionEvent e)
Object source = e.getSource();
if(source == exitButton)
exitProgram();
else if(source == abc[0]) //'A'
System.out.println("AAAAAAAAAA");
else if(source == abc[1]) //'B'
System.out.println("BBBBBBBBBB");
else if(source == abc[2]) //'C'
System.out.println("CCCCCCCCCC");
else if(source == abc[3]) //'D'
System.out.println("DDDDDDDDDD");
else if(source == abc[4]) //'E'
System.out.println("EEEEEEEEEE");
else if(source == abc[5]) //'F'
System.out.println("FFFFFFFFFF");
else if(source == abc[6]) //'G'
System.out.println("GGGGGGGGGG");
else if(source == abc[7]) //'H'
System.out.println("HHHHHHHHHH");
else if(source == abc[8]) //'I'
System.out.println("IIIIIIIIII");
else if(source == abc[9]) //'J'
System.out.println("JJJJJJJJJJ");
else if(source == abc[10])//'K'
System.out.println("KKKKKKKKKK");
else if(source == abc[11])//'L'
System.out.println("LLLLLLLLLL");
else if(source == abc[12])//'M'
System.out.println("MMMMMMMMMM");
else if(source == abc[13])//'N'
System.out.println("NNNNNNNNNN");
else if(source == abc[14])//'O'
System.out.println("OOOOOOOOOO");
else if(source == abc[15])//'P'
System.out.println("PPPPPPPPPP");
else if(source == abc[16])//'Q'
System.out.println("QQQQQQQQQQ");
else if(source == abc[17])//'R'
System.out.println("RRRRRRRRRR");
else if(source == abc[18])//'S'
System.out.println("SSSSSSSSSS");
else if(source == abc[19])//'T'
System.out.println("TTTTTTTTTT");
else if(source == abc[20])//'U'
System.out.println("UUUUUUUUUU");
else if(source == abc[21])//'V'
System.out.println("VVVVVVVVVV");
else if(source == abc[22])//'W'
System.out.println("WWWWWWWWWW");
else if(source == abc[23])//'X'
System.out.println("XXXXXXXXXX");
else if(source == abc[24])//'Y'
System.out.println("YYYYYYYYYY");
else if(source == abc[25])//'Z'
System.out.println("ZZZZZZZZZZ");
}//end of actionPerformed()
@Override
public void paint(Graphics brush)
super.paint(brush);
//Graphics2D g2D = (Graphics2D)brush;
}//end paint()
public void exitProgram()
int answer = 1;
answer = JOptionPane.showConfirmDialog(null,
"Do you want to quit?");
if(answer == 0)
System.exit(0);
}//end exitProgram()
}//end of class SecretPhraseUsingFile

Thanks JSG. Yeah, I definitely have too much in my constructor for sure. I just do that because I am uneasy about creating methods that I don't know how to use well. I am just now getting the hang of using try catch statements (they are very confusing!) and also knowing how to use FileStreams correctly (that took me forever to learn, and I still need work on it). I know that I need serious study of program architecture, how to design a program well. As for now, I'm content with smalll programs that at least work (albeit clunky).
I will try to implement your suggestions about the methods and about using super, I'm sure that I could do better with them. Thanks!

Similar Messages

  • Trouble getting any sound out of new Mac Pro

    I recently bought a new Mac Pro and I've been having trouble getting any sound out of the internal speaker. I believe it thinks that there are always headphones plugged in even when there aren't. I don't get a startup sound and it doesn't make the "volume change quack" when I change the volume. The choices under the Sound panel for Output are: "Headphones", "Line Out", and "Digital Out" even if no headphones are plugged in. Sometimes I can get sound out of the computer if I jiggle around a headphone plug in the jack but as soon as I reboot or the machine wakes up from sleep the sound goes away.
    I'm guessing that it's probably a bad headphone jack but before I inevitably have to lug the 60 pound machine to the Genius Bar I thought I'd ask to see if anyone else has had similar issues and if there might be a quick fix to do myself.
    Thanks for any tips or help.

    Thank you but that unfortunately did not fix it. I'm sure I need to take it in.

  • Trouble getting any response data

    Hi all,
    I have been having trouble with cref and CadDevice/CadDeviceInterface.
    I have my applet initialized and saved into a ROM; and then the ROM
    loaded is into cref. While cref waits for inputs I start an instance of
    CadDeviceInterface to exchange APDUs. The problem that I've been
    getting is that on selection the response is successful (0x9000)--
    but no data is contained in the response when it should contain
    the applet's AID.
    The other problems are function not found on reading data on the applet
    and on initializing parameter update.
    Does anyone knows what's the problem is here? I love any sort
    of suggestion.
    kl

    nevermind, i found the problem.

  • Please help - trouble getting any applet to run with Mozilla or IE?

    Hello,
    I am using Mozilla Firebird and MS IE 6 under WinXP Pro. I have installed JRE 1.4.2 and ensured that java is enabled in both browsers. But no matter what I do, no applet will run, at all. No classes are loaded, I just get an empty "resource not found" box. I must have installed the JRE 4 times now, and the process seems to finish flawlessly. Any ideas? Do I have to patch my windows? I would really like to test some java on this pc!!!!!!
    Thanks.

    I am using Mozilla Firebird and MS IE 6 under WinXP
    Pro. I have installed JRE 1.4.2 and ensured that java
    is enabled in both browsers. But no matter what I do,
    no applet will run, at all. No classes are loaded, I
    just get an empty "resource not found" box. I must
    have installed the JRE 4 times now, and the process
    seems to finish flawlessly. Any ideas? Do I have to
    patch my windows? I would really like to test some
    java on this pc!!!!!!Hi,
    this combination works fine for me!
    For Firebird check the Plugins Subdir or just write "abaout:plugins" the address field and hit enter. It should show you all plugins avail in Firebird.
    Enable the java console (not JavaScript!!) in the Java(TM) Plugin settings.
    Than a window whill show you "the work" of the Java Plugin.
    Hope this helps

  • I don't get VI errors but I am not getting any display.

    This is the problem that I am having, nothing seems to come into the Image Pixels (U8) on the Front panel. I don't get an image, the image box just stays white and nothing at all comes up for the pixels. What do you think is going on? I was wondering where I could probe the VI so that I could figure out if anything from the image is getting through. Where would I do that? I want to make sure the VI is getting something from the IMAQ board. Also what kind of probe would be the best to use? (I know it depends on what I am probing).
    Attachments:
    Acquire_Image_and_Save_Pixels_Without_Vision.vi ‏83 KB

    Try changing the input to the For Loop iteration terminal from 4 to 256, as done in the following example program.
    HL Grab in Picture Control:
    http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3EB3756A4E034080020E74861&p_node=DZ52505&p_source=External
    Hope this helps-
    Julie

  • Trouble getting 1130AG LWAPP to Connect to Controller

    I'm having trouble getting any of my 1130AG LWAPPs to connect to my WLC.
    I have not configured my DHCP server to deliver option 43 or option 60.
    However, I have manually configured the LWAPP using the CLI. I have assigned a static IP address, the default-gateway, gave it a hostname, and gave it the controller ip address.
    When I issue the command:
    show lwapp ip config
    all of the information appears correctly.
    However, the controller never registers the LWAPP.
    This is a completely new setup, so there are no previous configs to contend with.
    If I issue the command on the LWAPP:
    debug lwapp client event
    Two debug messages appear consistently every 3-5 seconds. They are:
    *Mar 1 00:34:26.733: LWAPP_CLIENT_EVENT: spamResolveStaticGateway - gateway found
    *Mar 1 00:34:36.733: LWAPP_CLIENT_EVENT: spamHandleDiscoveryTimer: Could not discover any MWAR
    Any suggestions?
    ~ Vance R. Gregory

    You have to put option 43 in hexadecimal no. below you will find an example of DHCP configurations on router that act as a DHCP for LWAPP in different network:
    ip dhcp excluded-address 172.16.1.1 192.168.1.1
    ip dhcp pool WAP_DHCP_SCOPE
    network 192.168.1.0 255.255.255.0
    option 43 hex f104c0a814f0
    The hex string is assembled by concatenating the TLV values shown below:
    Type + Length + Value
    Type is always f1(hex). Length is the number of controller management IP addresses times 4 in hex. Value is the IP address of the controller listed sequentially in hex.
    WLC IP is 192.168.20.240 f1+1*4+ac10.14f0 = f104c0a814f0
    default-router 192.168.1.1

  • I've got the labview vi written to read my IMU data from a serial port in COM1 and it displays onto the table on the front panel. I'm having trouble getting this data onto an excel spreadshee​t. Any ideas?

    I've got the labview vi written to read my IMU data from a serial port in COM1 and it displays onto the table on the front panel. I'm having trouble getting this data onto an excel spreadsheet. Any ideas? Right now my data will collect one reading instead of continuously reading my IMU which displays data in a continuous stream.
    Thanks
    Attachments:
    Read_IMU_Drew.vi ‏21 KB

    Hi
    Your vi is in 2009 version, which i am unable to open in 8.6
    However, if you want your data to be saved in excel sheet, here is the VI
    Somil Gautam
    Think Weird
    Attachments:
    save to excel.vi ‏12 KB

  • I'm having trouble getting a custom JPanel to display correctly...

    HI, I'm having trouble getting a custom JPanel to display correctly. I'm using the JPanel inside a JFrame to display some really custom graphs. The graphing side of this whole thing works flawlessly. The problem I'm having is that when I close the JFrame by using setVisible(false); and then openning it again using setVisible(true); all the information on it is garbage. There are buttons from the JFrame which orgininally opened it and it has trouble openning a second graph if I choose too. I also have the same problem if i move the frame off the screen and move it back. I'd really appreciate any help.
    Thanks!

    With option #1 -- I modified and rebuilt the 3rd-party JARs and referenced them in NetBeans. When I choose clean and build, the Ant processes results in an error: "jarsigner returns 1". So it doesn't seem to run at all.As long as you rebuilt the jars correctly without the original signature, I think it should work.
    An example of unsigning a jar using ant is here:
    http://frank.zinepal.com/unsign-a-jar-with-ant
    Do you think the multiple-JNLP idea would work if NetBeans didn't apply "my" signature to the 3rd-party JARs? Aside from manually copying the original JARs into the \dist directory, is there a better way to tell NetBeans to leave the 3rd-party JAR alone (ie, don't sign it again)?I think it's supposed to work (it's the mixed code signing situation I referred to in my prior post).
    For example, from your description it sounds like the default NetBeans build doesn't really support this style of deployment, so you would have to create a custom build which does what you need and is not triggered by NetBeans - which is doable, but annoying - it's sounds like you tried this, but were unable to get it to work as expected. For NetBeans specific help, you are better posting to a NetBeans forum (though you might be just the second person who has tried to do this with a JavaFX app).
    Also need to check the end user experience is acceptable too, because I think the dialog and warning handling for the mixed code situation is different.
    Look at the deployment guide section "Using <fx:resources> for Extension Descriptors" - I think it documents how to do what you want if you use a custom build file rather than letting NetBeans do the work:
    http://docs.oracle.com/javafx/2/deployment/javafx_ant_task_reference002.htm#CIABGCEE
    Hmm, a lot of running around to deploy an app which can open a file . . .

  • Hi, I am having trouble getting an album to download. I have tried it on both my iPhone and laptop through iTunes but neither works. I am wondering if it could be the size of the album stopping it downloading (212 Tracks) Any Ideas?

    Hi, I am having trouble getting an album to download. I have tried it on both my iPhone and laptop through iTunes but neither works. I am wondering if it could be the size of the album stopping it downloading (212 Tracks) Any Ideas?

    These alerts occur due to timeouts or conflicts trying to write a file during download.
    If you encounter this issue while while downloading something from the iTunes Store:
    Delete your iTunes Downloads folder, located in:
    Mac OS X:
  ~/Music/iTunes/iTunes Media/Downloads   Note: "iTunes Media" may appear as "iTunes Music. Also, the tilde (~)  refers to your Home directory.
    After locating your iTunes Downloads folder:
    Quit iTunes.
    Delete the Downloads folder on your computer.
    Open iTunes.
    Choose Store > Check for Available Downloads.
    Enter your account name and password.
    Also review this support aticle as it might be causing due to internet connection: http://support.apple.com/kb/ts1368
    Hope this helps.

  • I am having trouble getting a numbers spreadsheet to hold different formats in the same column.  A column with a date formatted heading will not convert to $ for the cells below.   Any suggestions would help.

    I am having trouble getting a numbers spreadsheet to hold different formats in the same column.  A column with a date formatted heading will not convert to $ for the cells below.   Any suggestions would help.

    Hi Wayne,
    Thank you for this response.  I have tried this but when I start enterring $ amounts some, such as $6.00, go in OK others such as $4.00 appear as a date ie 4 Oct 12.  
    Kind regards
    Paul

  • I'm having a trouble getting icloud mail without my personal email. All icloud features syncs unless mail didn't sync I am running mac ox 10.7.2 any ideas?

    I’m having a trouble getting icloud mail without my personal email. All icloud features syncs normally unless mail didn’t sync I am running mac ox 10.7.2 any ideas?

    I discovered that my cord was bad. I used someone else's cord and then it worked - that's how I was able to determine it was the cord, so I replaced it. (In case someone else has a similar problem.)
    BTW, I'm still having a problem syncing my iCal, so I posted that problem in the iCal forum. If you think you can help, please look for my message there.

  • Can't get any screen display (nano 7th gen)

    can't get any screen display (7th gen nano) -- yesterday had low battery and it may have been "a little sweaty" wet, charger all night -- still can't get it to "turn on"

    Hello garlaham,
    I would be concerned too if my iPod nano's was not powering on.  I recommend following the steps below:
    Will not turn on or screen remains dark
    Connect iPod to power for at least ten minutes to ensure that the battery has enough charge to allow iPod to turn on.
    If iPod does not turn on after ten minutes, try resetting the device while it is still connected to power. Press and hold the Sleep/Wake button and the Home button until the screen goes dark. The Apple logo should appear after a few seconds, then the Home screen should appear.
    If the Apple logo appears on the display, connect iPod to a computer and verify that it appears in iTunes and can play music. If iPod appears in iTunes and can play music, no further troubleshooting is needed.
    If the screen remains dark and will not turn on, then your iPod may need service.
    I got this information from the following article for the 6th generation iPod nano.  The steps are the same, except I updated the second step with the reset for the 7th generation iPod nano:
    iPod nano (6th generation): Hardware troubleshooting
    http://support.apple.com/kb/ts3474
    How to reset iPod
    http://support.apple.com/kb/ht1320
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Downloaded music apps o.k.  Says login failed when I put in user and password. No trouble when getting any other apps.

    Downloaded music apps o.k.  Says login failed when I put in user and password. No trouble when getting any other apps.

    Sounds like you may have deleted something you shouldn't have. Boot to an OS X DVD or a bootable backup, and using Disk Utility, do a repair disk, and while there repair permissions. Disconnect any peripherals, and reboot. If you get the same startup behavior, do a safe boot, by holding the shift key down when booting. If that works, try a normal boot. If neither step helps, you may need to relaod your operating system.

  • I cannot get any of the zoom functions to work, period. When Firefox starts up it begins to display the page then it stops and redisplays it. So its like it flashes on for a second then completely regoes to the site, any site. The text zooms dont work eve

    I cannot get any of the zoom functions to work, period. When Firefox starts up it begins to display the page then it stops and redisplays it. So its like it flashes on for a second then completely regoes to the site, any site. The text zooms dont work even when i try to change the font on the content tab, nothing. I have reinstalled firefox still no luck help,!!!!!
    == This happened ==
    Every time Firefox opened
    == this month ==
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; InfoPath.2)

    Do you have that problem when running in the Firefox SafeMode?
    [http://support.mozilla.com/en-US/kb/Safe+Mode]
    ''Don't select anything right now, just use "Continue in SafeMode."''
    If not, see this:
    [http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes]

  • I have an ut ipad 2 with no configuration for the i cloud. I have follow the instructions of synch the ipad with itunes v 10.6 in my pc, but i can not get the display of the cloud icon in the general settings of the ipad. appreciate any help

    I have an ut ipad 2 with no configuration for the i cloud. I have follow the instructions of synch the ipad with itunes v 10.6 in my pc, but i can not get the display of the cloud icon in the general settings of the ipad. appreciate any help

    I'm asking because ios5 introduced iCloud. You have to have updated to ios5 to see it.

Maybe you are looking for

  • BOM report showing materials and their prices

    Hi all, I'm trying to spool a report that shows the BOM materials and all their different prices so I can sum them up and know the total. I tried using CS13. I changed the layout so the display can include the standard prices of the materials(as main

  • Warning: ColorSync Profile change

    Warning: The default icc-color profile (ColorSync Profile) exporting images out of Aperture is sRGB! AND the Export Presets switch back to sRGB after changing. This happens with the own Export Presets too. I think this is a bug.

  • Java time counter ?

    Hi, Is there anyway to set time counter on java? My friend suggested that I can use util.date at the begining of my program and use it again at the end, after compare these two value, I can get the time period of the program. However, since util.date

  • Maniplating Spotlight Search Results

    When I open Entourage emails found in my Spotlight search results the date and time associated with the email automatically changes to today's date and time and the email - no matter how old it is - shows up as the first item in the list of found ite

  • TS3276 I cannot receive mail on my mac  computer- but am still getting it on my ipad?

    I haven't been able to receive my mail on my mac the past couple of days - but can still access it on my ipad?