Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

First Swing Applet

Status
Not open for further replies.

p3aul

Instructor
Jul 17, 2004
16
US
hi!I am using Jbuilder2006. I have a simple Swing applet with a button and a label. I double-clicked on the button and added this code:
jLabel3.text = "Hello";

I have attempted to do this like a Delphi statement. I'm probley wrong!

this is the error I got: "myswing.java": text has private access in javax.swing.JLabel at line 91, column 9

My jLabel3 is declared as public by default(written by JBuilder) How do I make it private? or is there another way?
Thanks in Advance!
Paul

The Bad News: Time Flies
The Good News: You are the Pilot
 
Try
Code:
jLabel3.setText("Hello");

Incidentally, you're going to get nowhere fast if you try using other languages as a basis for attemting valid Java syntax. You need to do some reading to get a grounding about how to structure classes and how to invoke methods on objects etc. One book I found useful is the 'Thinking In Java' by Bruce Eckel. You'll find it on the web with Google.

Tim
 
Thank you Tim!
Since I am so new at this I was trying to do something simple in terms that I already knew. Thats why I chose JBuilder. I firgured the folks at Borland would put out a Java product that would work similarly to Delphi or C++Builder. The Java language is so hard to learn with their mouselisteners and other odd programming constructs! It would have been just as easy to use Pascal or C++ syntax?
Paul

The Bad News: Time Flies
The Good News: You are the Pilot
 
Well, Java is an Object-Oriented language and the syntax is designed around this concept (so Pascal syntax, being non-OO, would obviously not do).

Java isn't just a matter of syntax, as you have noticed. We have constructs which may appear odd at first. They make more sense as you go along. The OO idea of code re-use extends to concept re-use too. Once you've 'got' how a MouseListener works, you're very likely to understand every other kind of Listener too.

The JBuilder IDE itself may look familiar to users of other Borland IDEs. I don't know. It does, however, handle Java like Java. There is no other way. Sun have specified the Java standard, not Borland.

Tim
 
Tim, Pascal is OO also. By Pascal I meant Object Pascal, but what I use is Delphi, based on the Pascal language. I noticed, after I double-clicked on the button, I didn't get a button-click event like in Delphi, but a actionPerformed event and instead of settting a property "text", I used a function, setText() to set the property. See, I am learning. By using Jbuilder, I didn't have to do all that coding as I would have to have done had I written the code in Notepad or some other text editor.
Again, thanks for your help!
Paul

The Bad News: Time Flies
The Good News: You are the Pilot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top