Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 7, 2016
0 parents
commit cb2bf52
Showing
1,055 changed files
with
14,251 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import java.awt.*; | ||
import java.awt.event.*; | ||
import javax.swing.*; | ||
|
||
public class ColorSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JColorChooser Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
final JButton button = new JButton("Pick to Change Background"); | ||
|
||
ActionListener actionListener = new ActionListener() { | ||
public void actionPerformed(ActionEvent actionEvent) { | ||
Color initialBackground = button.getBackground(); | ||
Color background = JColorChooser.showDialog(null, "JColorChooser Sample", initialBackground); | ||
if (background != null) { | ||
button.setBackground(background); | ||
} | ||
} | ||
}; | ||
button.addActionListener(actionListener); | ||
f.add(button, BorderLayout.CENTER); | ||
f.setSize (300, 200); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import java.awt.*; | ||
import javax.swing.*; | ||
|
||
public class DesktopSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JDesktopPane Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
JLayeredPane desktop = new JDesktopPane(); | ||
desktop.setOpaque(false); | ||
desktop.add (createLayer ("Open 1"), JLayeredPane.POPUP_LAYER); | ||
desktop.add (createLayer ("Iconified"), JLayeredPane.DEFAULT_LAYER); | ||
desktop.add (createLayer ("Open 2"), JLayeredPane.PALETTE_LAYER); | ||
f.add(desktop, BorderLayout.CENTER); | ||
f.setSize (300, 200); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
public static JInternalFrame createLayer (String label) { | ||
return new SelfInternalFrame(label); | ||
} | ||
static class SelfInternalFrame extends JInternalFrame { | ||
public SelfInternalFrame(String s) { | ||
getContentPane().add (new JLabel (s), BorderLayout.CENTER); | ||
setBounds (50, 50, 100, 100); | ||
setResizable (true); | ||
setClosable (true); | ||
setMaximizable (true); | ||
setIconifiable (true); | ||
setTitle (s); | ||
setVisible (true); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.awt.*; | ||
import javax.swing.*; | ||
|
||
public class EditorSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JEditorPane Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
JEditorPane editor = new JEditorPane("text/html", "<H3>Help</H3><center><IMG src=file:///c:/swing3/code/Ch01/logo.jpg></center><li>One<li><i>Two</i><li><u>Three</u>"); | ||
editor.setEditable(false); | ||
JScrollPane scrollPane = new JScrollPane(editor); | ||
f.add(scrollPane, BorderLayout.CENTER); | ||
f.setSize (300, 200); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.awt.*; | ||
import java.text.*; | ||
import javax.swing.*; | ||
import javax.swing.text.*; | ||
|
||
public class FormattedSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JFormattedTextField Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
Box rowOne = Box.createHorizontalBox(); | ||
rowOne.add(new JLabel("SSN:")); | ||
try { | ||
MaskFormatter mf1 = new MaskFormatter("###-##-####"); | ||
rowOne.add(new JFormattedTextField(mf1)); | ||
} catch (ParseException e) { | ||
} | ||
Box rowTwo = Box.createHorizontalBox(); | ||
rowTwo.add(new JLabel("Telephone #: ")); | ||
try { | ||
MaskFormatter mf2 = new MaskFormatter("(###) ###-####"); | ||
rowTwo.add(new JFormattedTextField(mf2)); | ||
} catch (ParseException e) { | ||
} | ||
f.add(rowOne, BorderLayout.NORTH); | ||
f.add(rowTwo, BorderLayout.SOUTH); | ||
f.setSize (300, 100); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import java.util.Vector; | ||
public class NamedVector extends Vector { | ||
String name; | ||
NamedVector(String name) { | ||
this.name = name; | ||
} | ||
NamedVector(String name, Object elements[]) { | ||
this.name = name; | ||
for (int i=0, n=elements.length; i<n; i++) { | ||
add(elements[i]); | ||
} | ||
} | ||
public String toString() { | ||
return name; | ||
} | ||
} | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.awt.*; | ||
import java.awt.event.*; | ||
import javax.swing.*; | ||
|
||
public class OptionPaneSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JOptionPane Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
JButton button = new JButton ("Ask"); | ||
ActionListener actionListener = new ActionListener() { | ||
public void actionPerformed(ActionEvent actionEvent) { | ||
Component source = (Component)actionEvent.getSource(); | ||
Object response = JOptionPane.showInputDialog( | ||
source, | ||
"Where do you want to go tomorrow?", | ||
"JOptionPane Sample", | ||
JOptionPane.QUESTION_MESSAGE, | ||
null, | ||
new String[] {"Tower of London", "Westminster Abbey", "Buckingham Palace", "Trafalgar Square", "Madame Tussaud's Wax Museum"}, | ||
"Westminster Abbey"); | ||
System.out.println ("Response: " + response); | ||
} | ||
}; | ||
button.addActionListener(actionListener); | ||
f.add(button, BorderLayout.CENTER); | ||
f.setSize (300, 200); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import java.awt.*; | ||
import javax.swing.*; | ||
|
||
public class PasswordSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JPasswordField Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
Box rowOne = Box.createHorizontalBox(); | ||
rowOne.add(new JLabel("Username")); | ||
rowOne.add(new JTextField()); | ||
Box rowTwo = Box.createHorizontalBox(); | ||
rowTwo.add(new JLabel("Password")); | ||
rowTwo.add(new JPasswordField()); | ||
f.add(rowOne, BorderLayout.NORTH); | ||
f.add(rowTwo, BorderLayout.SOUTH); | ||
f.setSize (300, 200); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import java.awt.*; | ||
import javax.swing.*; | ||
import javax.swing.border.*; | ||
|
||
public class ProgressSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JProgressBar Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
JProgressBar progressBar = new JProgressBar(); | ||
progressBar.setValue(25); | ||
progressBar.setStringPainted(true); | ||
Border border = BorderFactory.createTitledBorder("Reading..."); | ||
progressBar.setBorder(border); | ||
f.add(progressBar, BorderLayout.NORTH); | ||
f.setSize (300, 100); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import java.awt.*; | ||
import java.awt.event.*; | ||
import javax.swing.*; | ||
|
||
public class RadioButtonMenuSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JRadioButtonMenuItem Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
JMenuBar bar = new JMenuBar(); | ||
JMenu menu = new JMenu("Options"); | ||
menu.setMnemonic(KeyEvent.VK_O); | ||
|
||
ButtonGroup group = new ButtonGroup(); | ||
|
||
JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem("North"); | ||
group.add(menuItem); | ||
menu.add(menuItem); | ||
|
||
menuItem = new JRadioButtonMenuItem("East"); | ||
group.add(menuItem); | ||
menu.add(menuItem); | ||
|
||
menuItem = new JRadioButtonMenuItem("West"); | ||
group.add(menuItem); | ||
menu.add(menuItem); | ||
|
||
menuItem = new JRadioButtonMenuItem("South"); | ||
group.add(menuItem); | ||
menu.add(menuItem); | ||
|
||
menuItem = new JRadioButtonMenuItem("Center"); | ||
group.add(menuItem); | ||
menu.add(menuItem); | ||
|
||
bar.add(menu); | ||
f.setJMenuBar(bar); | ||
f.setSize (300, 200); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import java.awt.*; | ||
import javax.swing.*; | ||
|
||
public class SeparatorSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JSeparator Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
f.setLayout(new GridLayout(0, 1)); | ||
JLabel above = new JLabel("Above Separator"); | ||
f.add(above); | ||
JSeparator separator = new JSeparator(); | ||
f.add(separator); | ||
JLabel below = new JLabel("Below Separator"); | ||
f.add(below); | ||
f.setSize (300, 100); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import java.awt.*; | ||
import javax.swing.*; | ||
|
||
public class SliderSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JSlider Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
JSlider slider = new JSlider (); | ||
slider.setMinorTickSpacing (5); | ||
slider.setMajorTickSpacing (10); | ||
slider.setPaintTicks (true); | ||
slider.setSnapToTicks(true); | ||
slider.setPaintTrack (false); | ||
slider.setPaintLabels (true); | ||
f.add(slider, BorderLayout.CENTER); | ||
f.setSize (300, 100); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import java.awt.*; | ||
import javax.swing.*; | ||
import java.text.*; | ||
import java.util.*; | ||
|
||
public class SpinnerSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame f = new JFrame("JSpinner Sample"); | ||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH); | ||
String days[] = symbols.getWeekdays(); | ||
SpinnerModel model1 = new SpinnerListModel(days); | ||
SpinnerModel model2 = new SpinnerDateModel(); | ||
JSpinner spinner1 = new JSpinner(model1); | ||
JSpinner spinner2 = new JSpinner(model2); | ||
f.add(spinner1, BorderLayout.NORTH); | ||
f.add(spinner2, BorderLayout.SOUTH); | ||
f.setSize (300, 100); | ||
f.setVisible (true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.awt.*; | ||
import javax.swing.*; | ||
|
||
public class SplitSample { | ||
public static void main (String args[]) { | ||
Runnable runner = new Runnable() { | ||
public void run() { | ||
JFrame frame = new JFrame("JSplitPane Sample"); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
JSplitPane splitPane = new JSplitPane(); | ||
splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT); | ||
frame.add(splitPane, BorderLayout.CENTER); | ||
frame.setSize(300, 200); | ||
frame.setVisible(true); | ||
} | ||
}; | ||
EventQueue.invokeLater(runner); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.