Results 1 to 10 of 10
- 12-12-2010, 10:52 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
Can't have two JFrames in different classes?
This seems like it must be a standard thing that the textbooks warn you about, but I can't find it.
All of this occurred inside Eclipse, sometimes all in the same package, sometimes not.
I wrote a very simple class which used JFrame, along with JPanel and JLabel, to open a window with some text in it. That's all. I used
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
I can run the program several times and get the same result, it opens the window properly with the text in it every time.
Then I copied everything to a new class. Other than renaming the class, and the name of the file, everything was exactly the same. But instead of opening the window, it sends some unreadable output to the console.
The original program seems to be the only one that can open windows. Is this a feature? What do I do to get different programs to have the same functionality?
Thanks.
-
No. You've introduced a bug somehow.
The "unreadable" information is likely quite readable and informative, and without it and your code, we are probably not going to be able to help you.But instead of opening the window, it sends some unreadable output to the console.
Hard to say. Again, you'll likely want to post your code, if it's a reasonable size, and the error message. If you do post code, please read the link below on how to use code tags.The original program seems to be the only one that can open windows. Is this a feature? What do I do to get different programs to have the same functionality?
Much luck.
- 12-12-2010, 11:51 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
OK, here is the code, moused out of Eclipse. I couldn't find a special formatting option for code. It's supposed to exhibit a Vigenere square.
Java Code:package vigSquare; /** * @author alex * */ import javax.swing.*; import java.awt.*; public class Square extends JFrame { /** * */ private static final long serialVersionUID = 1L; private static final int FRAME_WIDTH = 800; private static final int FRAME_HEIGHT = 800; private JLabel inputLine; private String str; public static void main(String[] args) { Square myFrame = new Square(); myFrame.setVisible(true); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); myFrame.getContentPane().add(panel); myFrame.pack(); } public Square(){ getContentPane().setLayout(new GridLayout(27, 0)); str = new String("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"); inputLine = new JLabel(str); setSize(FRAME_WIDTH,FRAME_HEIGHT); setTitle("Vigenere Square"); for (int i = 0; i<26; i++){ inputLine = new JLabel(str.toString()); add(inputLine); str = str.substring(2) + " " + str.charAt(0); inputLine = new JLabel(str); } } }
And here is a little bit of output. It goes up to 2047. There were no error messages.
0
1
2
3
4
5
Moderator Edit: Code tags addedLast edited by Fubarable; 12-13-2010 at 12:32 AM. Reason: Moderator Edit: Code tags added
-
I've added code tags to your post above. To see how to do this yourself, again, please see the link in my signature below labeled "how to use code tags".
Your code looks OK. Now what happens when you try to copy it? Can you show the copied code and any error messages it produces?
- 12-13-2010, 12:59 AM #5
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
Thanks for the code tags. Got it. The output also included non-ascii characters that didn't show up when I posted.
This *is* the code that failed, and there were no error messages. It just didn't open a window, and printed (the wrong output, not a Vigenere square) to the console. It is the same as the code that worked, except for the names of the classes and the filename. Eclipse showed no errors and no warnings.
-
Hm, then I'm stumped, sorry. That being said, how are you copying the code? When I want to copy a file in Eclipse, I usually right-click on the file in the Package Explorer, then click "copy". Then I right click the package where I want the copy to go (or the same package if I want two copies in the same package), and then click "paste".
- 12-13-2010, 01:47 AM #7
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
Thanks. Yes, it is something very strange.
I just copied the code the way I would do it in a text editor - highlight, Ctrl-C, open the new file, Ctrl-V. I'll probably use your method (no pun intended) from now on.
- 12-13-2010, 07:09 PM #8
Member
- Join Date
- Oct 2010
- Posts
- 63
- Rep Power
- 0
Is the new file in the same package?
- 12-13-2010, 11:45 PM #9
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
I tried it both ways, first in the same package and then in a new one. Exited Eclipse in between. Same result.
- 12-14-2010, 03:25 AM #10
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
OK, it must be an Eclipse problem
I built both files in Eclipse, but then copied them out of the workspace and deleted the "package" declaration, and byte-compiled and ran both with "javac" and "java" at the command line, and both worked fine.
This is the Eclipse that came with the Ubuntu distribution. Anyone know if it is buggy this way?
Similar Threads
-
help with jframes
By pao09 in forum AWT / SwingReplies: 0Last Post: 04-15-2009, 02:10 PM -
jframes
By ddj in forum AWT / SwingReplies: 0Last Post: 03-24-2009, 03:15 PM -
linking 2 Jframes
By suhaib1thariq in forum New To JavaReplies: 9Last Post: 02-13-2009, 01:30 AM -
two JFrames
By kirtesh4u in forum New To JavaReplies: 0Last Post: 11-17-2008, 08:26 PM -
Handling Two JFrames
By hiranya in forum AWT / SwingReplies: 2Last Post: 11-05-2007, 07:23 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks