Skip to content

Commit e89542a

Browse files
committed
corejava第8版
1 parent 75e83a3 commit e89542a

File tree

522 files changed

+98293
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

522 files changed

+98293
-0
lines changed

corejava第8版/gutenberg/alice30.txt

Lines changed: 3852 additions & 0 deletions
Large diffs are not rendered by default.

corejava第8版/gutenberg/crsto10.txt

Lines changed: 62040 additions & 0 deletions
Large diffs are not rendered by default.
44.7 KB
Loading
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import java.awt.EventQueue;
2+
import java.awt.event.*;
3+
import java.io.*;
4+
import javax.swing.*;
5+
6+
/**
7+
* A program for viewing images.
8+
* @version 1.22 2007-05-21
9+
* @author Cay Horstmann
10+
*/
11+
public class ImageViewer
12+
{
13+
public static void main(String[] args)
14+
{
15+
EventQueue.invokeLater(new Runnable()
16+
{
17+
public void run()
18+
{
19+
JFrame frame = new ImageViewerFrame();
20+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21+
frame.setVisible(true);
22+
}
23+
});
24+
}
25+
}
26+
27+
/**
28+
* A frame with a label to show an image.
29+
*/
30+
class ImageViewerFrame extends JFrame
31+
{
32+
public ImageViewerFrame()
33+
{
34+
setTitle("ImageViewer");
35+
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
36+
37+
// use a label to display the images
38+
label = new JLabel();
39+
add(label);
40+
41+
// set up the file chooser
42+
chooser = new JFileChooser();
43+
chooser.setCurrentDirectory(new File("."));
44+
45+
// set up the menu bar
46+
JMenuBar menuBar = new JMenuBar();
47+
setJMenuBar(menuBar);
48+
49+
JMenu menu = new JMenu("File");
50+
menuBar.add(menu);
51+
52+
JMenuItem openItem = new JMenuItem("Open");
53+
menu.add(openItem);
54+
openItem.addActionListener(new ActionListener()
55+
{
56+
public void actionPerformed(ActionEvent event)
57+
{
58+
// show file chooser dialog
59+
int result = chooser.showOpenDialog(null);
60+
61+
// if file selected, set it as icon of the label
62+
if (result == JFileChooser.APPROVE_OPTION)
63+
{
64+
String name = chooser.getSelectedFile().getPath();
65+
label.setIcon(new ImageIcon(name));
66+
}
67+
}
68+
});
69+
70+
JMenuItem exitItem = new JMenuItem("Exit");
71+
menu.add(exitItem);
72+
exitItem.addActionListener(new ActionListener()
73+
{
74+
public void actionPerformed(ActionEvent event)
75+
{
76+
System.exit(0);
77+
}
78+
});
79+
}
80+
81+
private JLabel label;
82+
private JFileChooser chooser;
83+
private static final int DEFAULT_WIDTH = 300;
84+
private static final int DEFAULT_HEIGHT = 400;
85+
}
19.7 KB
Loading
21.5 KB
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* This program displays a greeting from the authors.
3+
* @version 1.20 2004-02-28
4+
* @author Cay Horstmann
5+
*/
6+
public class Welcome
7+
{
8+
public static void main(String[] args)
9+
{
10+
String[] greeting = new String[3];
11+
greeting[0] = "Welcome to Core Java";
12+
greeting[1] = "by Cay Horstmann";
13+
greeting[2] = "and Gary Cornell";
14+
15+
for (String g : greeting)
16+
System.out.println(g);
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<head>
3+
<title>WelcomeApplet</title>
4+
</head>
5+
<body>
6+
<hr/>
7+
<p>
8+
This applet is from the book
9+
<a href="http://www.horstmann.com/corejava.html">Core Java</a>
10+
by <em>Cay Horstmann</em> and <em>Gary Cornell</em>,
11+
published by Sun Microsystems Press.
12+
</p>
13+
<applet code="WelcomeApplet.class" width="400" height="200">
14+
<param name="greeting" value ="Welcome to Core Java!"/>
15+
</applet>
16+
<hr/>
17+
<p><a href="WelcomeApplet.java">The source.</a></p>
18+
</body>
19+
</html>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import java.awt.*;
2+
import java.awt.event.*;
3+
import java.net.*;
4+
import javax.swing.*;
5+
6+
/**
7+
* This applet displays a greeting from the authors.
8+
* @version 1.22 2007-04-08
9+
* @author Cay Horstmann
10+
*/
11+
public class WelcomeApplet extends JApplet
12+
{
13+
public void init()
14+
{
15+
EventQueue.invokeLater(new Runnable()
16+
{
17+
public void run()
18+
{
19+
setLayout(new BorderLayout());
20+
21+
JLabel label = new JLabel(getParameter("greeting"), SwingConstants.CENTER);
22+
label.setFont(new Font("Serif", Font.BOLD, 18));
23+
add(label, BorderLayout.CENTER);
24+
25+
JPanel panel = new JPanel();
26+
27+
JButton cayButton = new JButton("Cay Horstmann");
28+
cayButton.addActionListener(makeAction("http://www.horstmann.com"));
29+
panel.add(cayButton);
30+
31+
JButton garyButton = new JButton("Gary Cornell");
32+
garyButton.addActionListener(makeAction("mailto:gary_cornell@apress.com"));
33+
panel.add(garyButton);
34+
35+
add(panel, BorderLayout.SOUTH);
36+
}
37+
});
38+
}
39+
40+
private ActionListener makeAction(final String urlString)
41+
{
42+
return new ActionListener()
43+
{
44+
public void actionPerformed(ActionEvent event)
45+
{
46+
try
47+
{
48+
getAppletContext().showDocument(new URL(urlString));
49+
}
50+
catch (MalformedURLException e)
51+
{
52+
e.printStackTrace();
53+
}
54+
}
55+
};
56+
}
57+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
2+
/* DO NOT EDIT */
3+
4+
grant {
5+
permission java.security.AllPermission;
6+
};
7+

0 commit comments

Comments
 (0)