| Author |
shortcuts like VB's "with" keyword
|
Donald R. Cossitt
buckaroo
Ranch Hand
Joined: Jan 31, 2003
Posts: 401
|
|
I am very new to Java, though have about 10 years with VB. What I would like to know is there a process of shortcut that would allow not repeating object / method repition? eg public class TryFlowLayout { static JFrame aWindow = new JFrame("Flow Layout Window by DOCO"); public static void main (String[] args) { Toolkit theKit = aWindow.getToolkit(); Dimension wndSize = theKit.getScreenSize(); aWindow.setBounds(wndSize.width / 4, wndSize.height / 4, 600, wndSize.height / 2); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FlowLayout flow = new FlowLayout(); Container content = aWindow.getContentPane(); content.setLayout(flow); for (int i = 0; i <= 6; i++) content.add(new JButton("Press " + i)); aWindow.setVisible(true); } } Replace the repition of aWindow for instance: {... With aWindow .setBounds(...); .getContentPane(...); .setVisible(...); End With ...} Sure would be handy if there were TIA doco
|
doco
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
|
There is no such shortcut in Java.
|
Java API Documentation
The Java Tutorial
|
 |
Donald R. Cossitt
buckaroo
Ranch Hand
Joined: Jan 31, 2003
Posts: 401
|
|
I was afraid of that seing I could not find anything in docs. Thanks doco
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Notice that a "with" statement would mostly be used where you had the code smell "Feature Envy" - a part of the code of an object seems to be more interested about another object than about itself. For your own designs, you should think hard about moving that piece of code into the other class - sadly, you can't do this for third party libraries in Java, of course. http://c2.com/cgi/wiki?FeatureEnvy
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Donald R. Cossitt
buckaroo
Ranch Hand
Joined: Jan 31, 2003
Posts: 401
|
|
Thanks, I suppose the biggest problem I am going to have is shaking the VB out of my brain. It was not OO but object based - subtle but important difference. What you stated is a perfect example I suppose. Thanks doco
|
 |
 |
|
|
subject: shortcuts like VB's "with" keyword
|
|
|