Results 1 to 4 of 4
Thread: Popup JFrame
- 12-04-2010, 04:20 AM #1Member
- Join Date
- Oct 2010
- Rep Power
Essentially, what I have is a very basic photoshop. A few of the features require some sort of pop up dialog that will display statistics for the image, or take input from the user to imply onto the image. Now, I have all the code written for actually working on the image itself (I've tested it and it works), but this is my first time working with JFrame and the like. That being said, I need a dialog to pop up when, for instance, the user clicks the Resize button and take input. That input then needs to be stored to a variable - from there, I have it.
If it helps, I attached my code as a .txt document. I didn't just post it here because of how long it is...
Thanks for any help!!!
- 12-04-2010, 05:21 AM #2
If the code is too long to post in a forum, it's too long for me to be interested to go through. Recommended reading:
How To Ask Questions The Smart Way
SSCCE : Java Glossary
How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
and the rest of the Swing tutorial.
- 12-04-2010, 05:52 AM #3Member
- Join Date
- Oct 2010
- Rep Power
The tutorial actually did help a lot. I've gotten this far now;
JFrame brightenDiag = new JFrame (); brightenDiag.setSize(400, 200); brightenDiag.setResizable(false); brightenDiag.setTitle("Brighten Image"); brightenDiag.setVisible(true); JPanel JPANEL_BD = new JPanel(); brightenDiag.add(JPANEL_BD,BorderLayout.SOUTH); JLabel JLABEL_BDL = new JLabel(); brightenDiag.add(JLABEL_BDL,BorderLayout.NORTH); JButton okButton = new JButton("OK"); okButton.setBounds(0, 0, 75, 75); okButton.addActionListener(this); JPANEL_BD.add(okButton); JLABEL_BDL.add("Enter a positive integer between 0 and 255 to increase the brightness."); JTextField inputLine1; JPANEL_BD.add(inputLine1);
But I keep getting an error saying that "JLABEL_BDL.add("Enter a positive integer between 0 and 255 to increase the brightness.");" isn't a variable, which I fully understand why. What I don't understand is how to create a static text field that says what I have in the quotes. I know the tutorial explained this, but I couldn't really follow.
As Darryl suggests, you should create a small compilable program that we can run, test and modify that shows your problem, an SSCCE. If you post this, you'll likely get a helpful answer quickly. I have to ask why you are calling add on a JLabel? Please look at the API and you'll see that this is not what add is for, that you'll likely rarely if ever need to call this on a JLabel, and if you do call it on a JComponent, you don't pass a String into this method, but rather a Component. Perhaps you wanted to call setText(...) instead? I also see that it attempts to mix console with gui in a bad way. Get rid of all code that requires users to enter information on the console. Also, you will want to read up on how to use layout managers.
- By anix in forum NetBeansReplies: 5Last Post: 06-14-2010, 07:10 PM
- By Robert_85 in forum Advanced JavaReplies: 4Last Post: 04-23-2009, 12:02 AM
- By Arsenic in forum Java AppletsReplies: 3Last Post: 04-10-2009, 09:37 PM
- By jiexx in forum New To JavaReplies: 1Last Post: 03-24-2009, 02:58 AM
- By nilz in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 11-20-2007, 05:29 PM