Java s GUI-k a - sze

23
Java Appletek I. Java és GUI-k

Transcript of Java s GUI-k a - sze

Page 1: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

Java Appletek I.

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

Java és GUI-k

Page 2: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

3

Webtechnológia 1

AWT, Swing

• Abstract Window Toolkit

• sok UI komponens

• eseménykezelés

• grafikus eszközök

• layout managerek

• Swing

• pluggable look & feel

• lightweight UI Framework

• magas szint! komponensek

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

4

Webtechnológia 1

MVC és Swing alkalmazás

View Controller Model

Window obj. Listener obj. Data obj.Events Messages

Update

Java UI components

Page 3: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

5

Webtechnológia 1

Swing áttekintés

• JComponent

• Az alkalmazás vagy applet összes látható eleme component

• A Container osztály példányai komponensek csoportjait tartalmazzák

• add metódus

2

2000 Prentice Hall, Inc. All rights reserved.

3

12.2 Swing Overview

• Swing component inheritance hierarchy

• Component defines methods that can be used in itssubclasses (for example, paint and repaint)

• Container - collection of related components

– When using JFrames, attach components to the contentpane (a Container)

– Method add• JComponent - superclass to most Swing components

• Much of a component's functionality inherited from theseclasses

java.awt.Component

java.awt.Container

java.lang.Object

javax.swing.JComponent

2000 Prentice Hall, Inc. All rights reserved.

4

12.2 Swing Overview

• Some capabilities of subclasses of JComponent– Pluggable look and feel

– Shortcut keys (mnemonics)

• Direct access to components through keyboard

– Common event handling

• If several components perform same actions

– Tool tips

• Description of component that appears when mouse over it

• Swing vs. awt?

– Different components

• Java 1.0 vs. Java 1.1 vs. Java 1.2?

– Different event model

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

6

Webtechnológia 1

Swing áttekintés (folyt.)

• JComponent legfontosabb tulajdonságai

• pluggable look&feel

• shortcut keys

• közös eseménykezelés lehetséges

• tool tipek

• Swing vagy AWT

• különböz" komponensek

Page 4: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

7

Webtechnológia 1

Java eseménykezelési modellje

• Eseményvezérelt GUI

• eseménygenerálás, ha a felhasználó interakcióba lép egy GUI komponenssel

• esemény infók tárolása AWTEvent leszármazottakban

• Események feldolgozása

• eseményfigyel" regisztrálása

• event-listener interface implementálása

• eseménykezel" implementálása

• eseményre válaszul meghívandó metódusok

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

8

Webtechnológia 1

Java eseménykezelési modellje (folyt.)

• Delegációs esemény modell

• esemény figyel"k használata

• az objektum számára érdekes események feldolgozása

• Esemény bekövetkeztekor

• GUI komponens értesíti a figyel"ket

• figyel" meghívja az eseménykezel" metódust

Page 5: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

9

Webtechnológia 1

Események

• Különféle események

• ActionEvent

• képerny"gomb megnyomása

• AdjustmentEvent

• scrollbar mozgatása

• MouseEvent

• egér koordináták

• KeyEvent

• billenty! kód, karakter

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

10

Webtechnológia 1

Adapter osztályok

• El"regyártott Adapter osztályok

• Listener interface-eket implementáló abstract osztályok

• leszármaztatottban a kívánt metódus felülírható

Page 6: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

11

Webtechnológia 1

Swing komponensekés az MVC

• Maguk a Swing komponensek MVC struktúrájúak

• JComponent-eknek van model-jük

• pl. JButton -> ButtonModel

• view és controller absztrakt UI delegáltakban

• javax.swing.plaf

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

12

Webtechnológia 1

Swing osztályok

JComponent

JTextComponent

AbstractButton

JComboBox

JLabel

JList

JMenuBar

JPane

JPopupMenu

JScrollbar

JScrollPane

JTable

JTree

JToggleButton JButton JMenuItem

JCheckBox JRadioButton

JRadioButtonMenuItem JCheckBoxMenuItem

ContainerComponentObject

JPanel

JApplet

AppletPanel

JMenu

FontColor

JTextAreaJTextField

Page 7: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

13

Webtechnológia 1

Swing GUI komponensek

Demo program at jdk1.4/demo/jfc/SwingSet2/SwingSet2.html

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

14

Webtechnológia 1

Layout kezelés

• Automatikus átrendezés

Page 8: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

15

Webtechnológia 1

Border layout

public class TestBorderLayout extends JApplet { public void init() { Container guiContainer = getContentPane(); Font big = new Font("SansSerif", Font.BOLD, 20); JButton buttonOne = new JButton("1"); buttonOne.setFont(big); guiContainer.add(buttonOne, BorderLayout.WEST); JButton buttonTwo = new JButton("2"); buttonTwo.setFont(big); guiContainer.add(buttonTwo, BorderLayout.CENTER); JButton buttonThree = new JButton("3"); buttonThree.setFont(big); guiContainer.add(buttonThree, BorderLayout.EAST); JButton buttonFour = new JButton("4"); buttonFour.setFont(big); guiContainer.add(buttonFour, BorderLayout.NORTH); JButton buttonFive = new JButton("5"); buttonFive.setFont(big); guiContainer.add(buttonFive, BorderLayout.SOUTH); }}

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

16

Webtechnológia 1

GridLayoutpublic class TestGridLayout extends JApplet { private JTextField name = new JTextField(15); private JTextField address = new JTextField(15); private JTextField phone = new JTextField(15); private JTextField eMail = new JTextField(15);

public void init() { Container guiContainer = getContentPane(); guiContainer.setLayout(new GridLayout(4, 2, 5, 5));

JLabel label = new JLabel("Name:", JLabel.RIGHT); guiContainer.add(label); guiContainer.add(name); label = new JLabel("Address:", JLabel.RIGHT); guiContainer.add(label); guiContainer.add(address); label = new JLabel("Phone:", JLabel.RIGHT); guiContainer.add(label); guiContainer.add(phone); label = new JLabel("E-mail:", JLabel.RIGHT); guiContainer.add(label); guiContainer.add(eMail); }}

Page 9: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

17

Webtechnológia 1

GridBagLayout

• GridBagLayout is the most general of all the layout managers, and often the only applicable.

• It’s not suited for the trial end error method.

• To use it you have to do a careful planning. Use pen and paper!

• The manager has many parameters, and an error may give unpredictable results.

• First, create a sketch of the window:

• Divide the window into rectangular cells by using vertical and horizontal lines.

• Not more than one GUI component in every cell.

• A GUI component may cover more than one cell.

• This sketch makes it possible to state the requirements of every component.

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

18

Webtechnológia 1

GridBag példa

toolbar

table on

the left

list on

the right

backgr. text

at the ottom

text box at

the bottom

gridx 0 0 3 1 2

gridy 0 1 1 2 2

gridwidth 4 3 1 1 1

gridheight 1 1 1 1 1

fill NONE BOTH BOTH NONE HORIZONTAL

anchor WEST CENTER CENTER EAST WEST

0

1

2

0 1 2 3

Page 10: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

19

Webtechnológia 1

GridBag példa (folyt.)

Container guiContainer = getContentPane();

guiContainer.setLayout(new GridBagLayout()); // don’t forget this!

GridBagConstraints constraints = new GridBagConstraints();

/* The following variables are fixed for all components */

constraints.insets = new Insets(5, 5, 5, 5); // space around and between the components

constraints.weightx = 0.5;

constraints.weighty = 0.5;

/* Then each component has to be handled according to the table */

/* The Toolbar */

constraints.gridx = 0;

constraints.gridy = 0;

constraints.gridwidth = 4;

constraints.gridheight = 1;

constraints.fill = GridBagConstraints.NONE;

constraints.anchor = GridBagConstraints.WEST;

guiContainer.add(toolbar, constraints);

// ..and so on, for all the components

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

Appletek

Page 11: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

21

Webtechnológia 1

Hello world applet

import javax.swing.JApplet;

import java.awt.Graphics;

public class HelloWorld extends JApplet {

public void paint(Graphics g) {

g.drawRect(0, 0,

getSize().width - 1,

getSize().height - 1);

g.drawString("Hello world!", 5, 15);

}

}

<applet code="HelloWorld.class" codebase="examples/" archive="helloWorld.jar" width="150" height="30"></applet>

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

22

Webtechnológia 1

Appletek

Object

Component

JFrame JApplet

JInternalFrame Dialog

JDialog

Container

WindowJComponent Panel

FrameJWindow Applet

Page 12: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

23

Webtechnológia 1

Appletek (folyt.)

• grafikus kisalkalmazás

• böngész" vagy appletviewer kontextus

• java.applet.Applet vagy javax.swing.JApplet specializálása

• standard interfész

• homokozó (sandbox)

• SecurityManager

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

24

Webtechnológia 1

Appletéletciklus

The applet is stopped, the user has left theWeb page.

init() start()

start()

stop()

destroy()

The applet isloaded and startsright away.

The applet isrunning, theuser is watching.

The applet is out of theworld because thebrowser is closed, or foranother reason.

loaded running stopped dead

Page 13: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

25

Webtechnológia 1

Appletéletciklus (folyt.)

/*

* Java(TM) SE 6 Version

*/

import java.applet.Applet;

import java.awt.Graphics;

//No need to extend JApplet, since we don't add any components;

//we just paint.

public class Simple extends Applet {

StringBuffer buffer;

public void init() {

buffer = new StringBuffer();

addItem("initializing... ");

}

public void start() {

addItem("starting... ");

}

public void stop() {

addItem("stopping... ");

}

public void destroy() {

addItem("preparing for unloading...");

}

private void addItem(String newWord) {

System.out.println(newWord);

buffer.append(newWord);

repaint();

}

public void paint(Graphics g) {

//Draw a Rectangle around the applet's display area.

g.drawRect(0, 0,

getWidth() - 1,

getHeight() - 1);

//Draw the current string inside the rectangle.

g.drawString(buffer.toString(), 5, 15);

}

}

appletviewer lifeCycle.html

initializing...

starting...

stopping...

preparing for unloading...

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

26

Webtechnológia 1

Appletéletciklus (folyt.)

• init metódus

• constructor szer! m!veletek elvégzése, teljes contextus

• start metódus

• az applet tevékenysége

• szálak indítása

• stop metódus

• er"források elengedése

Page 14: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

27

Webtechnológia 1

Megjelenítés

• Applet megjelenítés a paint metódussal

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

28

Webtechnológia 1

Eseménykezelés/*

* Java(TM) SE 6 version.

*/

import java.awt.event.MouseListener;

import java.awt.event.MouseEvent;

import java.applet.Applet;

import java.awt.Graphics;

//No need to extend JApplet, since we don't add any components;

//we just paint.

public class SimpleClick extends Applet

implements MouseListener {

StringBuffer buffer;

public void init() {

addMouseListener(this);

buffer = new StringBuffer();

addItem("initializing... ");

}

public void start() {

addItem("starting... ");

}

public void stop() {

addItem("stopping... ");

}

public void destroy() {

addItem("preparing for unloading...");

}

void addItem(String newWord) {

System.out.println(newWord);

buffer.append(newWord);

repaint();

}

public void paint(Graphics g) {

//Draw a Rectangle around the applet's display area.

g.drawRect(0, 0,

getWidth() - 1,

getHeight() - 1);

//Draw the current string inside the rectangle.

g.drawString(buffer.toString(), 5, 15);

}

//The following empty methods could be removed

//by implementing a MouseAdapter (usually done

//using an inner class).

public void mouseEntered(MouseEvent event) {

}

public void mouseExited(MouseEvent event) {

}

public void mousePressed(MouseEvent event) {

}

public void mouseReleased(MouseEvent event) {

}

public void mouseClicked(MouseEvent event) {

addItem("click!... ");

}

}

Page 15: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

29

Webtechnológia 1

UI komponensek appletben

• Swing komponensek

• Applet -> Container

• add, remove

• setLayout

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

30

Webtechnológia 1

UI komponensek appletben (pl.)

/*

* Java(TM) SE 6 version.

*/

import javax.swing.JApplet;

import javax.swing.JTextField;

import javax.swing.SwingUtilities;

//Since we're adding a Swing component, we now need to

//extend JApplet. We need to be careful to access

//components only on the event-dispatching thread.

public class ScrollingSimple extends JApplet {

JTextField field;

public void init() {

//Execute a job on the event-dispatching thread:

//creating this applet's GUI.

try {

SwingUtilities.invokeAndWait(new Runnable() {

public void run() {

createGUI();

}

});

} catch (Exception e) {

System.err.println("createGUI didn't successfully complete");

}

addItem(false, "initializing... ");

}

private void createGUI() {

//Create the text field and make it uneditable.

field = new JTextField();

field.setEditable(false);

//Set the layout manager so that the text field will be

//as wide as possible.

getContentPane().setLayout(new java.awt.GridLayout(1,0));

//Add the text field to the applet.

getContentPane().add(field);

}

public void start() {

addItem(false, "starting... ");

}

public void stop() {

addItem(false, "stopping... ");

}

public void destroy() {

addItem(false, "preparing for unloading...");

cleanUp();

}

Page 16: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

31

Webtechnológia 1

UI komponensek appletben (pl.)

private void cleanUp()

//Execute a job on the event-dispatching thread:

//taking the text field out of this applet.

try {

SwingUtilities.invokeAndWait(new Runnable() {

public void run() {

remove(field);

}

});

} catch (Exception e) {

System.err.println("cleanUp didn't successfully complete");

}

field = null;

}

private void addItem(boolean alreadyInEDT, String newWord) {

if (alreadyInEDT) {

addItem(newWord);

} else {

final String word = newWord;

//Execute a job on the event-dispatching thread:

//invoking addItem(newWord).

try {

SwingUtilities.invokeAndWait(new Runnable() {

public void run() {

addItem(word);

}

});

} catch (Exception e) {

System.err.println("addItem didn't successfully complete");

}

}

}

//Invoke this method ONLY from the event-dispatching thread.

private void addItem(String newWord) {

String t = field.getText();

System.out.println(newWord);

field.setText(t + newWord);

}

}

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

32

Webtechnológia 1

A homokozó

• browser security policy

• SecurityManager

• SecurityException

• korlátozások

• An applet cannot load libraries or define native methods.

• It cannot ordinarily read or write files on the host that's executing it.

• It cannot make network connections except to the host that it came from.

• It cannot start any program on the host that's executing it.

• It cannot read certain system properties.

• Windows that an applet brings up look di#erent than windows that an application brings up.

Page 17: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

33

Webtechnológia 1

Applet sajátosságok

• Alkalmazásoktól eltér" lehet"ségek

• Applets can usually make network connections to the host they came from.

• Applets running within a Web browser can easily cause HTML documents to be displayed.

• Applets can invoke public methods of other applets on the same page.

• Applets that are loaded from the local file system (from a directory in the user's CLASSPATH) have none of the restrictions that applets loaded over the network do.

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

34

Webtechnológia 1

Az applet API

• Az appletek az API-n keresztül

• értesülhetnek az applet futási állapotváltozásairól

• az applet vagy beágyazó oldal URL-jéhez relatív elérési utakkal fájlokat tölthetnek le

• írhatnak a browser státusz-sorába

• megjeleníthatnek dokumentumokat a browserben

• paramétereket olvashatnak az applet tagb"l

Page 18: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

35

Webtechnológia 1

Fájlok letöltése

• getCodeBase

• getDocumentBase

• getImage

• gif, jpeg

• MediaTracker

• getAudioClip

• wav,midi,ai#,au

• URL osztály

class file

a.png

imgDir

Image image = getImage(getCodeBase(), "imgDir/a.png");

com xcompany xproj

class file

a.png

imgDir

package com.xcompany.xproj;

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

36

Webtechnológia 1

MediaTracker// Create a MediaTracker instance,

// to montior loading of images

tracker = new MediaTracker(this);

// Load the image

Image img = getImage( getDocumentBase(),"picture.jpg" );

// Register it with media tracker

tracker.addImage(img, 1);

// Check to see if it has loaded

if (tracker.checkID(1) == false)

{

// Not yet, display message .....

}

else

{

// Display the animation

}

// Wait until all images have loaded

tracker.waitForAll();

Page 19: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

37

Webtechnológia 1

Fájlok letöltése (pl.)

import javax.swing.*;

import java.awt.*;

/** Demonstrate drawing an image. **/

public class ImageApplet extends JApplet

{

public void init () {

Container content_pane = getContentPane ();

// Grab the image.

Image img = getImage (getCodeBase (), "liftoff.jpg");

// Create an instance of DrawingPanel

DrawingPanel drawing_panel = new DrawingPanel (img);

// Add the DrawingPanel to the contentPane.

content_pane.add (drawing_panel);

} // init

} // ImageApplet

/** Draw on a JPanel rather than on JApplet's Panel. **/

class DrawingPanel extends JPanel {

Image img;

DrawingPanel (Image img) {

this.img = img;

}

public void paintComponent (Graphics g) {

super.paintComponent (g);

// Use the image width& width to find the starting point

int img_x = getSize ().width/2 - img.getWidth (this)/2;

int img_y = getSize ().height/2 - img.getHeight (this)/2;

//Draw image at centered in the middle of the panel

g.drawImage (img, img_x, img_y, this);

} // paintComponent

} // class DrawingPanel

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

38

Webtechnológia 1

Dokumentum megjelenítés a böngész!ben

• public void showDocument(java.net.URL url)

• public void showDocument(java.net.URL url, String targetWindow)

• browser ablakok

• _blank

• új, névtelen ablak

• _self

• az applet ablaka

• _parent

• keretek esetén a frameset ablaka

• _top

• legmagasabb szint! frameset ablaka

Page 20: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

39

Webtechnológia 1

Dokumentum megjelenítés a böngész!ben (pl.)

/*

* Java(TM) SE 6 version.

*/

import java.applet.AppletContext;

import javax.swing.*;

import java.awt.GridBagLayout;

import java.awt.GridBagConstraints;

import java.awt.Insets;

import java.awt.event.*;

import java.net.URL;

import java.net.MalformedURLException;

public class ShowDocument extends JApplet

implements ActionListener {

URLWindow urlWindow;

public void init() {

//Execute a job on the event-dispatching thread:

//creating this applet's GUI.

try {

SwingUtilities.invokeAndWait(new Runnable() {

public void run() {

createGUI();

}

});

} catch (Exception e) {

System.err.println("createGUI didn't successfully complete");

}

}

private void createGUI() {

JButton button = new JButton("Bring up URL window");

button.addActionListener(this);

getContentPane().add(button);

JFrame.setDefaultLookAndFeelDecorated(true);

urlWindow = new URLWindow(getAppletContext());

urlWindow.pack();

}

public void destroy() {

//Execute a job on the event-dispatching thread:

//creating this applet's GUI.

try {

SwingUtilities.invokeAndWait(new Runnable() {

public void run() {

destroyGUI();

}

});

} catch (Exception e) { }

}

private void destroyGUI() {

urlWindow.setVisible(false);

urlWindow = null;

}

public void actionPerformed(ActionEvent event) {

urlWindow.setVisible(true);

}

}

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

40

Webtechnológia 1

Dokumentum megjelenítés a böngész!ben (pl.)

class URLWindow extends JFrame

implements ActionListener {

JTextField urlField;

JComboBox choice;

AppletContext appletContext;

public URLWindow(AppletContext appletContext) {

super("Show a Document!");

this.appletContext = appletContext;

JPanel contentPane = new JPanel(new GridBagLayout());

setContentPane(contentPane);

contentPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

GridBagConstraints c = new GridBagConstraints();

c.fill = GridBagConstraints.HORIZONTAL;

JLabel label1 = new JLabel("URL of document to show: ",

JLabel.TRAILING);

getContentPane().add(label1, c);

urlField = new JTextField("http://java.sun.com/", 20);

label1.setLabelFor(urlField);

urlField.addActionListener(this);

c.gridwidth = GridBagConstraints.REMAINDER;

c.weightx = 1.0;

getContentPane().add(urlField, c);

JLabel label2 = new JLabel("Window/frame to show it in: ",

JLabel.TRAILING);

c.gridwidth = 1;

c.weightx = 0.0;

getContentPane().add(label2, c);

String[] strings = {

"(browser's choice)", //don't specify

"My Personal Window", //a window named "My Personal Window"

"_blank", //a new, unnamed window

"_self",

"_parent",

"_top" //the Frame that contained this applet

};

choice = new JComboBox(strings);

label2.setLabelFor(choice);

c.fill = GridBagConstraints.NONE;

c.gridwidth = GridBagConstraints.REMAINDER;

c.insets = new Insets(5,0,0,0);

c.anchor = GridBagConstraints.LINE_START;

getContentPane().add(choice, c);

JButton button = new JButton("Show document");

button.addActionListener(this);

c.weighty = 1.0;

c.ipadx = 10;

c.ipady = 10;

c.insets = new Insets(10,0,0,0);

c.anchor = GridBagConstraints.PAGE_END;

getContentPane().add(button, c);

}

Page 21: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

41

Webtechnológia 1

Dokumentum megjelenítés a böngész!ben (pl.)

public void actionPerformed(ActionEvent event) {

String urlString = urlField.getText();

URL url = null;

try {

url = new URL(urlString);

} catch (MalformedURLException e) {

System.err.println("Malformed URL: " + urlString);

}

if (url != null) {

if (choice.getSelectedIndex() == 0) {

appletContext.showDocument(url);

} else {

appletContext.showDocument(url,

(String)choice.getSelectedItem());

}

}

}

}

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

42

Webtechnológia 1

Státusz-sor

• átmeneti státusz információk kiírása

import!java.applet.AppletContext;

import!java.awt.Graphics;

import!java.net.URL;

import!javax.swing.JApplet;

public!class!MainClass!extends!JApplet!{

!!public!void!paint(Graphics!g)!{

!!!!AppletContext!ac!=!getAppletContext();

!!!!try!{

!!!!!!URL!url!=!new!URL("http://www.java2s.com");

!!!!!!ac.showDocument(url,!"frame2");

!!!!}!catch!(Exception!e)!{

!!!!!!showStatus("Exception:!"!+!e);

!!!!}

!!!!g.drawString("ShowDocument!Applet",!10,!25);

!!}

}

Page 22: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

43

Webtechnológia 1

Applet paraméterek

• commandline paraméterekhez hasonló használat

• flexibilis felhasználás

• paraméterek

• név

• értékkészlet

• default érték

<APPLET CODE=SampleApplet.class CODEBASE=example

WIDTH=350 HEIGHT=60>

<PARAM NAME=windowClass VALUE=BorderWindow>

<PARAM NAME=windowTitle VALUE="BorderLayout">

<PARAM NAME=buttonText

VALUE="Click here to see a BorderLayout in action">

</APPLET>

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

44

Webtechnológia 1

Applet paraméterek (folyt.)

public String getParameter(String name)

int requestedWidth = 0; //default value

. . .

String windowWidthString = getParameter("WINDOWWIDTH");

if (windowWidthString != null) {

try {

requestedWidth = Integer.parseInt(windowWidthString);

} catch (NumberFormatException e) {

//Use default width.

}

}

Page 23: Java s GUI-k a - sze

THEINTERNET,mapped on the opposite page, is a scale-free network in that

some siteS (starbursts and detail above) have a seemingly unlimitednumber of connections to other sites. This map, made on February 6, 2003,

traces the shortest routes from atest WebsinHo about 100,000 others,

using like colors for similar Webaddresses.

a -

Scientistshaverecentlydiscoveredthat variouscomplexsystemshave

antlnderlyihg~..'~tJ;i~e~tu"eg~Ye'l"rne(;lb9.$haredorganili ngprincipies.

Thisinsighthas important impli~ationsfor a hostof

applications,fromdrugdevelopmentto Internetsecurity

BYALBERT-U\SZLOBARABASIANDERICBONABEAU

50 SCIENTIFIC AMERICAN MAY 2003

45

Webtechnológia 1

Applet paraméterek (folyt.)

• Paraméter információk megadásapublic String[][] getParameterInfo() {

String[][] info = {

// Parameter Name Kind of Value Description

{"imagesource", "URL", "a directory"},

{"startup", "URL", "displayed at startup"},

{"background", "URL", "displayed as background"},

{"startimage", "int", "start index"},

{"endimage", "int", "end index"},

{"namepattern", "URL", "used to generate indexed names"},

{"pause", "int", "milliseconds"},

{"pauses", "ints", "milliseconds"},

{"repeat", "boolean", "repeat or not"},

{"positions", "coordinates", "path"},

{"soundsource", "URL", "audio directory"},

{"soundtrack", "URL", "background music"},

{"sounds", "URLs", "audio samples"},

};

return info;

}