1 / 8

CSCI 201 GUIs, Graphics, and Events

CSCI 201 GUIs, Graphics, and Events. Java Graphics (awt). Some AWT components support drawing import java.awt.*; public class ... extends Frame { ... Put drawing code in: public void paint(Graphics g) { ... }. x. 0, 0. y. Hi!. Java Graphics continued. Drawing commands:

amaya-kirk
Download Presentation

CSCI 201 GUIs, Graphics, and Events

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. CSCI 201 GUIs, Graphics, and Events

  2. Java Graphics (awt) • Some AWT components support drawing import java.awt.*; public class ... extends Frame { ... • Put drawing code in: public void paint(Graphics g) { ... } x 0, 0 y

  3. Hi! Java Graphics continued • Drawing commands: g.drawLine(x1, y1, x2, y2); g.drawRect(x, y, width, height); g.drawOval(x, y, width, height); g.fillRect(x, y, width, height); g.fillOval(x, y, width, height); g.setColor(Color.RED); g.drawString("Hi!", x, y);

  4. GUI (= Graphical User Interface) • Components: • new Canvas(); • new Button("click me!"); • new Label ("Hi"); • new Choice(); • new Panel(); • … Use Drawing commands Use “add” to add menu items Use “add” to add other components

  5. Layout Managers • setLayout(new …); • FlowLayout() • add(…); • GridLayout(nrows, ncols) • add(…); • BorderLayout() • add("Center", …); • add("North", …);

  6. Layout Example

  7. Events import java.awt.event.*; public class … implements ActionListener quitButton.addActionListener(this); public void actionPerformed(ActionEvent evt) { if (evt.getSource() == quitButton) { … } }

  8. Applets import java.applet.*; public class MyApplet extends Applet { public void init() { // instead of constructor } } Include in HTML: <applet code="MyApplet.class" width=500 height=400> </applet>

More Related