1 / 13

Java Network Programming

Java Network Programming. CSD008 Week 4. Topics for this week. GUIs JBuilder’s GUI Designer Applet s More GUI components Last week we looked at Panel s and Label s This week we will look at Button s, TextField s and TextArea s. Create a new Applet.

fisseha
Download Presentation

Java Network Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Network Programming CSD008 Week 4

  2. Topics for this week • GUIs • JBuilder’s GUI Designer • Applets • More GUI components • Last week we looked at Panels and Labels • This week we will look at Buttons, TextFields and TextAreas

  3. Create a new Applet • Follow the instructions from week 3, part 2 to: • Create a new project called week4part1 • Create an Applet called ButtonTester • Add a Panel (from AWT menu)called mainPanel to the Center of the Applet using BorderLayout • Change the Layout of mainPanel to XYLayout • Add a Label called messageLabel that contains the text “Messages will appear here” • Run the Applet to make sure it’s what we want

  4. The New Applet Your new applet should look like this when you run it

  5. a. Click on the button in the Toolbar for creating Buttons, then drag on the mainPanel to draw it Add a Button

  6. a. Now change the name of the button to changeTextButton and change the label of it to “Press Me” Edit the Button

  7. a. Double-click on the Button you have just drawn and you will brought to some code, we add code where the cursor is b. This is a method (remember Objects and method etc) that is called every time the Button is pressed Functionality of the Button

  8. a. Write the code you want to be executed when the changeTextButton is pressed within this method. We will take a simple example that just prints a message every time the button is pressed. Code for the Button Now run the Applet and test it!!

  9. Button Code cont’d • Now lets change the code so that rather than printing the message, it will display a message in messageLabel • Note that setText(String text) is a method of the class Label Now run the Applet and test it!!

  10. Input of Text • Now we will add a TextField so that a user can input text to the program • Go into the designer again, and in the same way as before (the Label and Button) pick the TextField from the Toolbar and draw it on to mainPanel • Name this object inputTextField and change its text to “input text here”

  11. Display the Input Text • Now lets edit the Buttons functionality again so that it displays the text from inputTextField in the messageLabel Now run the Applet and test it!!

  12. Related Tasks • Experiment with the following in an Applet (i.e. try setting or reading their values etc) • TextAreas – very similar to TextField • ScrollPane – you can insert TextAreas in these so you can scroll through a large amount of text • (Optional) If there are any other objects you’d like to understand try using them

  13. Comments • It is essential that you understand and can reproduce on your own everything we have done so far • Week 1: Basics of Java • Week 2: OOP • Week 3 / 4: GUIs • Always keep a backup of your work • Start a new project every week or any time you start a new program

More Related