mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-16 05:15:22 +00:00
7027700: /jfc/SwingApplet demo needs to be improved
Reviewed-by: alexp
This commit is contained in:
parent
7fbd444883
commit
c19fe5a5d0
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -29,42 +29,59 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.net.*;
|
||||
import java.applet.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.FlowLayout;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JApplet;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
|
||||
/**
|
||||
* A very simple applet.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SwingApplet extends JApplet {
|
||||
|
||||
JButton button;
|
||||
|
||||
public void init() {
|
||||
|
||||
// Force SwingApplet to come up in the System L&F
|
||||
String laf = UIManager.getSystemLookAndFeelClassName();
|
||||
private void initUI() {
|
||||
// Trying to set Nimbus look and feel
|
||||
try {
|
||||
UIManager.setLookAndFeel(laf);
|
||||
// If you want the Cross Platform L&F instead, comment out the above line and
|
||||
// uncomment the following:
|
||||
// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
||||
} catch (UnsupportedLookAndFeelException exc) {
|
||||
System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
|
||||
} catch (Exception exc) {
|
||||
System.err.println("Error loading " + laf + ": " + exc);
|
||||
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(SwingApplet.class.getName()).
|
||||
log(Level.SEVERE, "Failed to apply Nimbus look and feel", ex);
|
||||
}
|
||||
|
||||
getContentPane().setLayout(new FlowLayout());
|
||||
button = new JButton("Hello, I'm a Swing Button!");
|
||||
getContentPane().add(button);
|
||||
getContentPane().doLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
initUI();
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(SwingApplet.class.getName()).
|
||||
log(Level.SEVERE, null, ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
Logger.getLogger(SwingApplet.class.getName()).
|
||||
log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (button != null) {
|
||||
getContentPane().remove(button);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user