Results 1 to 2 of 2
- 09-30-2009, 01:09 PM #1
Senior Member
- Join Date
- Sep 2009
- Location
- Sweden/Borås
- Posts
- 107
- Rep Power
- 0
Is this a "good" way to handle classes?
Hi, Im trying to learn how classes and method´s really work. After reading and trying i come up with.
Would like some critique.Java Code:import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JTextField; public class test1 { private JTextField createText(){ JTextField aTextField; aTextField = new JTextField(); return aTextField; } private JMenuBar createMenu() { JMenuBar aMenuBar; JMenu aMenu; aMenuBar = new JMenuBar(); aMenu = new JMenu("Arkiv 1"); aMenuBar.add(aMenu); return aMenuBar; } private static void gui() { JFrame aFrame = new JFrame("gui"); aFrame.setVisible(true); test1 menu = new test1(); aFrame.setJMenuBar(menu.createMenu()); test1 text = new test1(); aFrame.add(text.createText()); aFrame.setSize(200, 200); aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { gui(); } }Last edited by ocean; 09-30-2009 at 01:19 PM.
- 09-30-2009, 01:51 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You realize that
can be collapsed intoJava Code:private JTextField createText(){ JTextField aTextField; aTextField = new JTextField(); return aTextField; }
Which should get you into thinking about whether you really need that method at all.Java Code:private JTextField createText(){ return new JTextField(); }
If you are learning about methods don't bring Swing into it. Swing is a different beast altogether which you would need to learn later after understanding the methods basics.
Similar Threads
-
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 03:03 AM -
getDisplayLanguage returns "en" not "English"
By DD70 in forum New To JavaReplies: 6Last Post: 08-12-2009, 11:22 PM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
Making A Set Of Classes "Importable"
By JDCAce in forum Advanced JavaReplies: 4Last Post: 12-05-2008, 09:11 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks