import javax.swing.*;
class FrameMethod {
public static void main(String args][]){
new frame;
}
public static frame
{
JFrame frame = new JFrame("Frame");
frame.setSize(500, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
frame.setVisible(true);
}
}
Method to create JFrame
Page 1 of 14 Replies - 840 Views - Last Post: 01 January 2013 - 03:45 PM
#1
Method to create JFrame
Posted 01 January 2013 - 03:37 PM
I want to create a method so that I can call it whenever I want to create a JFrame, and not have to type out all of the frame. stuff. Would this simplified code work?
Replies To: Method to create JFrame
#2
Re: Method to create JFrame
Posted 01 January 2013 - 03:40 PM
No. Your code won't even compile. Make sure to test your code, and you can determine if it will work or not.
#3
Re: Method to create JFrame
Posted 01 January 2013 - 03:41 PM
Is there any other way to do what I originally proposed?
#4
Re: Method to create JFrame
Posted 01 January 2013 - 03:42 PM
Did you even test that? What that frame is? a class or a method?
You can simply have a class inherited from a JFrame and then whenever you want to create a frame, then create an object of it. All those things can be done in its constructor which is called automatically when you create an object...
You can simply have a class inherited from a JFrame and then whenever you want to create a frame, then create an object of it. All those things can be done in its constructor which is called automatically when you create an object...
#5
Re: Method to create JFrame
Posted 01 January 2013 - 03:45 PM
An inheritance model is another way of accomplishing modularizing a JFrame. I have a tutorial on Swing for Beginners.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote







|