-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8357176: java.awt javadoc code examples still use Applet API #25278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -240,15 +240,15 @@ | |||||
* left-to-right container and Figure 3 shows the layout for a horizontal, | ||||||
* right-to-left container. | ||||||
* | ||||||
* <div style="margin:0 auto;width:680px;text-align:center;font-weight:bold"> | ||||||
* <div style="margin:0 auto;width:850px;text-align:center;font-weight:bold"> | ||||||
* <div style="float:left"> | ||||||
* <p><img src="doc-files/GridBagLayout-1.gif" | ||||||
* <p><img src="doc-files/GridBagLayout-1.png" | ||||||
* alt="The preceding text describes this graphic (Figure 2)." | ||||||
* style="margin: 7px 10px;"> | ||||||
* <p>Figure 2: Horizontal, Left-to-Right | ||||||
* </div> | ||||||
* <div style="float:right"> | ||||||
* <p><img src="doc-files/GridBagLayout-2.gif" | ||||||
* <p><img src="doc-files/GridBagLayout-2.png" | ||||||
* alt="The preceding text describes this graphic (Figure 3)." | ||||||
* style="margin: 7px 10px;"> | ||||||
* <p>Figure 3: Horizontal, Right-to-Left | ||||||
|
@@ -277,70 +277,64 @@ | |||||
* Here is the code that implements the example shown above: | ||||||
* | ||||||
* <hr><blockquote><pre> | ||||||
* import java.awt.*; | ||||||
* import java.util.*; | ||||||
* import java.applet.Applet; | ||||||
* import java.awt.Button; | ||||||
* import java.awt.EventQueue; | ||||||
* import java.awt.Frame; | ||||||
* import java.awt.GridBagConstraints; | ||||||
* import java.awt.GridBagLayout; | ||||||
* | ||||||
* public class GridBagEx1 extends Applet { | ||||||
* public class GridBagLayoutExample { | ||||||
* | ||||||
* protected void makebutton(String name, | ||||||
* GridBagLayout gridbag, | ||||||
* GridBagConstraints c) { | ||||||
* Button button = new Button(name); | ||||||
* gridbag.setConstraints(button, c); | ||||||
* add(button); | ||||||
* } | ||||||
* static void addButton(String name, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* GridBagLayout gridbag, | ||||||
* GridBagConstraints c, | ||||||
* Frame frame) { | ||||||
* Button button = new Button(name); | ||||||
* gridbag.setConstraints(button, c); | ||||||
* frame.add(button); | ||||||
* } | ||||||
Comment on lines
+288
to
+295
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||
* | ||||||
* public void init() { | ||||||
* GridBagLayout gridbag = new GridBagLayout(); | ||||||
* GridBagConstraints c = new GridBagConstraints(); | ||||||
* public static void main(String[] args) throws Exception { | ||||||
* | ||||||
* setFont(new Font("SansSerif", Font.PLAIN, 14)); | ||||||
* setLayout(gridbag); | ||||||
* EventQueue.invokeAndWait(() -> { | ||||||
* Frame frame = new Frame("GridBagLayout"); | ||||||
* GridBagLayout gridbag = new GridBagLayout(); | ||||||
* GridBagConstraints c = new GridBagConstraints(); | ||||||
* frame.setLayout(gridbag); | ||||||
Comment on lines
+297
to
+303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||
* | ||||||
* c.fill = GridBagConstraints.BOTH; | ||||||
* c.weightx = 1.0; | ||||||
* makebutton("Button1", gridbag, c); | ||||||
* makebutton("Button2", gridbag, c); | ||||||
* makebutton("Button3", gridbag, c); | ||||||
* c.fill = GridBagConstraints.BOTH; | ||||||
* c.weightx = 1.0; | ||||||
* addButton("Button1", gridbag, c, frame); | ||||||
* addButton("Button2", gridbag, c, frame); | ||||||
* addButton("Button3", gridbag, c, frame); | ||||||
* | ||||||
* c.gridwidth = GridBagConstraints.REMAINDER; //end row | ||||||
* makebutton("Button4", gridbag, c); | ||||||
* c.gridwidth = GridBagConstraints.REMAINDER; //end row | ||||||
* addButton("Button4", gridbag, c, frame); | ||||||
* | ||||||
* c.weightx = 0.0; //reset to the default | ||||||
* makebutton("Button5", gridbag, c); //another row | ||||||
* c.weightx = 0.0; //reset to the default | ||||||
* addButton("Button5", gridbag, c, frame); //another row | ||||||
* | ||||||
* c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row | ||||||
* makebutton("Button6", gridbag, c); | ||||||
* c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row | ||||||
* addButton("Button6", gridbag, c, frame); | ||||||
* | ||||||
* c.gridwidth = GridBagConstraints.REMAINDER; //end row | ||||||
* makebutton("Button7", gridbag, c); | ||||||
* c.gridwidth = GridBagConstraints.REMAINDER; //end row | ||||||
* addButton("Button7", gridbag, c, frame); | ||||||
* | ||||||
* c.gridwidth = 1; //reset to the default | ||||||
* c.gridheight = 2; | ||||||
* c.weighty = 1.0; | ||||||
* makebutton("Button8", gridbag, c); | ||||||
* c.gridwidth = 1; //reset to the default | ||||||
* c.gridheight = 2; | ||||||
* c.weighty = 1.0; | ||||||
* addButton("Button8", gridbag, c, frame); | ||||||
* | ||||||
* c.weighty = 0.0; //reset to the default | ||||||
* c.gridwidth = GridBagConstraints.REMAINDER; //end row | ||||||
* c.gridheight = 1; //reset to the default | ||||||
* makebutton("Button9", gridbag, c); | ||||||
* makebutton("Button10", gridbag, c); | ||||||
* c.weighty = 0.0; //reset to the default | ||||||
* c.gridwidth = GridBagConstraints.REMAINDER; //end row | ||||||
* c.gridheight = 1; //reset to the default | ||||||
* addButton("Button9", gridbag, c, frame); | ||||||
* addButton("Button10", gridbag, c, frame); | ||||||
* | ||||||
* setSize(300, 100); | ||||||
* } | ||||||
* | ||||||
* public static void main(String args[]) { | ||||||
* Frame f = new Frame("GridBag Layout Example"); | ||||||
* GridBagEx1 ex1 = new GridBagEx1(); | ||||||
* | ||||||
* ex1.init(); | ||||||
* | ||||||
* f.add("Center", ex1); | ||||||
* f.pack(); | ||||||
* f.setSize(f.getPreferredSize()); | ||||||
* f.show(); | ||||||
* } | ||||||
* frame.pack(); | ||||||
* frame.setVisible(true); | ||||||
* }); | ||||||
* } | ||||||
* } | ||||||
* </pre></blockquote><hr> | ||||||
* | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||
/* | ||||||
* Copyright (c) 1995, 2024, Oracle and/or its affiliates. All rights reserved. | ||||||
* Copyright (c) 1995, 2025, Oracle and/or its affiliates. All rights reserved. | ||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||||||
* | ||||||
* This code is free software; you can redistribute it and/or modify it | ||||||
|
@@ -68,13 +68,16 @@ | |||||
* Here is an example of using {@code MediaTracker}: | ||||||
* | ||||||
* <hr><blockquote><pre>{@code | ||||||
* import java.applet.Applet; | ||||||
* import java.awt.Color; | ||||||
* import java.awt.EventQueue; | ||||||
* import java.awt.Frame; | ||||||
* import java.awt.Image; | ||||||
* import java.awt.Graphics; | ||||||
* import java.awt.MediaTracker; | ||||||
* import java.awt.Panel; | ||||||
* import java.awt.Toolkit; | ||||||
* | ||||||
* public class ImageBlaster extends Applet implements Runnable { | ||||||
* public class MediaTrackerExample extends Panel implements Runnable { | ||||||
* MediaTracker tracker; | ||||||
* Image bg; | ||||||
* Image anim[] = new Image[5]; | ||||||
|
@@ -84,28 +87,33 @@ | |||||
* // Get the images for the background (id == 0) | ||||||
* // and the animation frames (id == 1) | ||||||
* // and add them to the MediaTracker | ||||||
* public void init() { | ||||||
* public static void main(String[] args) throws Exception { | ||||||
* MediaTrackerExample mte = new MediaTrackerExample(); | ||||||
* EventQueue.invokeAndWait(() -> { | ||||||
* Frame frame = new Frame("MediaTrackerExample"); | ||||||
* frame.setSize(400, 400); | ||||||
* frame.add(mte); | ||||||
* frame.setVisible(true); | ||||||
* }); | ||||||
* mte.startAnimation(); | ||||||
* } | ||||||
* | ||||||
* public MediaTrackerExample() { | ||||||
* Toolkit tk = Toolkit.getDefaultToolkit(); | ||||||
* tracker = new MediaTracker(this); | ||||||
* bg = getImage(getDocumentBase(), | ||||||
* "images/background.gif"); | ||||||
* // Note : actual images not provided as part of this code example | ||||||
* bg = tk.getImage("background.gif"); | ||||||
* tracker.addImage(bg, 0); | ||||||
* for (int i = 0; i < 5; i++) { | ||||||
* anim[i] = getImage(getDocumentBase(), | ||||||
* "images/anim"+i+".gif"); | ||||||
* anim[i] = tk.getImage("anim"+i+".gif"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* tracker.addImage(anim[i], 1); | ||||||
* } | ||||||
* } | ||||||
* | ||||||
* // Start the animation thread. | ||||||
* public void start() { | ||||||
* public void startAnimation() { | ||||||
* animator = new Thread(this); | ||||||
* animator.start(); | ||||||
* } | ||||||
* | ||||||
* // Stop the animation thread. | ||||||
* public void stop() { | ||||||
* animator = null; | ||||||
* } | ||||||
* } | ||||||
* | ||||||
* // Run the animation thread. | ||||||
* // First wait for the background image to fully load | ||||||
|
@@ -152,7 +160,7 @@ | |||||
* public void paint(Graphics g) { | ||||||
* if ((tracker.statusAll(false) & MediaTracker.ERRORED) != 0) { | ||||||
* g.setColor(Color.red); | ||||||
* g.fillRect(0, 0, size().width, size().height); | ||||||
* g.fillRect(0, 0, getSize().width, getSize().height); | ||||||
* return; | ||||||
* } | ||||||
* g.drawImage(bg, 0, 0, this); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The images would look better with square borders… which are left on Windows 10 only. If it's possible to make the pixels on the rounded corners transparent or at least white, the images would look better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to keep the width small as it was?