• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

shortcuts like VB's "with" keyword

 
buckaroo
Posts: 401
Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no such shortcut in Java.
 
Donald R. Cossitt
buckaroo
Posts: 401
Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was afraid of that seing I could not find anything in docs.
Thanks
doco
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Donald R. Cossitt
buckaroo
Posts: 401
Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic