Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

GUIs Part Two - Introduduction to Jave Programming - Lecture Slides, Slides of Java Programming

In the course of the Introduction to Jave Programming, we study the basic syntax and the basic program in java. In these lecture slides the key points are: Guis, Make Windows, Put Stuff in Windows, Sequential, Event Driven, Sequential Programming, Beginning, Time, Exceptions, Program

Typology: Slides

2012/2013

Uploaded on 04/23/2013

sarmistha
sarmistha 🇮🇳

3.8

(22)

113 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
GUIs part 2
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download GUIs Part Two - Introduduction to Jave Programming - Lecture Slides and more Slides Java Programming in PDF only on Docsity!

GUIs part 2

Docsity.com

Announcements

  • Lab Monday will be non-graded GUI lab (You may come and work on previous lab)
  • Homework due Monday Docsity.com

ImageIcon class

Previously we used JLabels to hold text We can also use JLabel to hold an image:

  1. Make an ImageIcon object
  2. Make a JLabel object
  3. Link them together (See: DrawImages.java) Docsity.com

Extending JFrame

To do some more advanced drawing, we will have to extend JFrame (to override methods): Then we need to override the paint() method: DrawCircle is just an example name Docsity.com

When to repaint?

Java normally updates your GUI automatically Sometimes you need to update manually: repaint - redraw the whole window pack - resize the window revalidate - layout is redone (in case you removed any objects) If your window seems to not be correct (or not updating) try running one/all of theseDocsity.com

Graphics + Mouse

We have seen how to detect when you click the mouse, so let's use that to draw! To do this we need to make a MouseListener:

  • When press the mouse down, mark this as one corner of the rectangle
  • When we release the mouse, mark this as the other end of the rectangle (mini-paint!) (See: MouseDraw.java) Docsity.com

JColorChooser

The JColorChooser is a pre-built class that allows you to choose a color (from a GUI) To run the GUI, use showDialog() (returns Color): (See: RainbowMouseDraw.java) associated window title of color GUI initial color selected Docsity.com

drawString()

You can also use the Graphics class to draw a more customizable String than JLabel To do need to simply call drawString(): Can also change Font with: (See: DrawStringExample.java) starting x pixel starting y pixel point size Docsity.com