This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes shortcuts like VB's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "shortcuts like VB Watch "shortcuts like VB New topic

shortcuts like VB's "with" keyword

Donald R. Cossitt
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);
FlowLayout flow = new FlowLayout();
Container content = aWindow.getContentPane();
for (int i = 0; i <= 6; i++)
content.add(new JButton("Press " + i));
Replace the repition of aWindow for instance:
With aWindow
End With
Sure would be handy if there were

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
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
I was afraid of that seing I could not find anything in docs.
Ilja Preuss

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.

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
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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: shortcuts like VB's "with" keyword
Similar Threads
Swing & Awt on Windows XP
Can someone plz check it
Can't find itself
Repaint component through functioncall