public class Java_1
{
//*********Found**********
public static void main (String args[])
{
new SimpleThread("第1").start();
new SimpleThread("第2").start();
}
}
//*********Found**********
class SimpleThread extends Thread
{
public SimpleThread(String str)
{
super(str);
}
public void run()
{
for (int i = 0; i < 5; i++)
{
//*********Found**********
System.out.println(i + " " + getName());
try
{
sleep((int)(2 * 100));
}
catch (InterruptedException e) { }
}
System.out.println("运行! " + getName());
}
}
import java.text.*;
public class Java_2
{
public static void main(String[] args)
{
Person[] people = new Person[2];
people[0] = new Worker("老张", 30000);
people[1] = new Student("小王", "计算机科学");
for (int i = 0; i < people.length; i++)
{
Person p = people[i];
//*********Found**********
System.out.println(p.getName() + ", " + p.getDescription());
}
}
}
//*********Found**********
abstract class Person
{
public Person(String n)
{
name = n;
}
//*********Found**********
public abstract String getDescription();
public String getName()
{
return name;
}
private String name;
}
//*********Found**********
class Worker extends Person
{
public Worker(String n, double s)
{
super(n);
salary = s;
}
public String getDescription()
{
NumberFormat formatter = NumberFormat.getCurrencyInstance();
return "工人,年薪是 " + formatter.format(salary) + "。";
}
private double salary;
}
//*********Found**********
class Student extends Person
{
public Student(String n, String m)
{
super(n);
major = m;
}
public String getDescription()
{
return "学生,专业是 " + major + "。";
}
private String major;
}
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class Java_3
{
public static void main(String[] args)
{
JFrame frame = new ImageViewerFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//*********Found**********
frame.setVisible(true);
}
}
class ImageViewerFrame extends JFrame
{
private JLabel label;
private JLabel labelT;
private JFileChooser chooser;
private JComboBox faceCombo;
private static final int DEFAULT_SIZE = 24;
public static final int DEFAULT_WIDTH = 570;
public static final int DEFAULT_HEIGHT = 400;
public ImageViewerFrame()
{
setTitle("ImageViewer");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
label = new JLabel();
Container contentPane = getContentPane();
contentPane.add(label,BorderLayout.CENTER);
chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
//*********Found**********
JMenu menu = new JMenu("file");
menuBar.add(menu);
JMenuItem openItem = new JMenuItem("Open");
//*********Found**********
menu.add(openItem);
openItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
int r = chooser.showOpenDialog(null);
if(r == JFileChooser.APPROVE_OPTION)
{
//*********Found**********
String name = chooser.getSelectedFile().getPath();
label.setIcon(new ImageIcon(name));
}
}
});
labelT = new JLabel("红军不怕远征难");
labelT.setFont(new Font("隶书", Font.PLAIN, DEFAULT_SIZE));
contentPane.add(labelT, BorderLayout.NORTH );
faceCombo = new JComboBox();
faceCombo.setEditable(true);
faceCombo.addItem("隶书");
faceCombo.addItem("华文新魏");
faceCombo.addItem("华文行楷");
faceCombo.addItem("华文隶书");
faceCombo.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
//*********Found**********
labelT.setFont(new Font((String)faceCombo.getSelectedItem(),
Font.PLAIN, DEFAULT_SIZE));
}
});
JPanel comboPanel = new JPanel();
comboPanel.add(faceCombo);
contentPane.add(comboPanel, BorderLayout.SOUTH);
}
}