Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
for0231 committed Jan 25, 2013
0 parents commit ea842d5
Show file tree
Hide file tree
Showing 597 changed files with 26,068 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.swp
/Example/nbproject/private/
/Example/build/
/Example/dist/
55 changes: 55 additions & 0 deletions AppPara.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.Date;
public class AppPara extends Applet
{
String strTime = new String();
static String strUser = new String();
static boolean inApplet = true;
public void init()
{
if (inApplet)
{
strUser = getParameter("USER");
}
}
public void start()
{
Date d = new Date();
strTime = d.toString();
repaint();
}
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawString(strUser + "你好,当前的时间为: " + strTime, 20, 30);
}

public static void main(String[] args)
{
inApplet = false;
if (args.length < 1)
{
System.out.println("缺少用户参数");
System.exit(0);
}
else
strUser = new String(args[0]);
Frame f=new Frame("时间");
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});

AppPara a = new AppPara();
a.init();
f.add("Center", a);
f.setSize(400,200);
f.show();
a.start();
}
}
48 changes: 48 additions & 0 deletions AppletSecurity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;

public class AppletSecurity extends Applet
{
TextField fileNameField;
TextArea fileArea;
public void init()
{
Label lblName = new Label("文件名: ");
Label lblContext = new Label("文件内容: ");
fileNameField = new TextField(35);
fileNameField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loadFile(fileNameField.getText());
}
});
fileArea = new TextArea(10, 35);
add(lblName);
add(fileNameField);
add(lblContext);
add(fileArea);
}

public void loadFile(String fileName)
{
try
{
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String context = new String();
while ((context = reader.readLine()) != null)
{
fileArea.append(context + "\n");
}
reader.close();
}
catch(IOException ie)
{
fileArea.append("IO错误: " + ie.getMessage());
}
catch(SecurityException se)
{
fileArea.append("安全访问错误: " + se.getMessage());
}
}
}
20 changes: 20 additions & 0 deletions Company/Manager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Company; // 声明名Company
class Employee
{
public String name;
public int salary;
public String getSalary()
{
String str;
str = "名字:" + name + "\nSalary:" + salary;
return str;
}
}
public class Manager extends Employee
{
public String department;
public String getSalary()
{
return super.getSalary() + "\nDepartment:" + department;
}
}
Binary file added Example/chap01/实例1/BorderLayoutDemo.class
Binary file not shown.
20 changes: 20 additions & 0 deletions Example/chap01/实例1/BorderLayoutDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.awt.*;
import java.applet.*;
import java.util.*;

public class BorderLayoutDemo extends Applet
{
public void init()
{
setLayout(new BorderLayout());

add(new Button("This is arross the top"),
BorderLayout.NORTH);
add(new Label("The message is on the bottom"),
BorderLayout.SOUTH);
add(new Button("Left"),BorderLayout.WEST);
add(new Button("Right"),BorderLayout.EAST);
String message="This is the message in the Center!";
add(new TextArea(message),BorderLayout.CENTER);
}
}
Binary file added Example/chap01/实例1/BoxLayoutFrame.class
Binary file not shown.
40 changes: 40 additions & 0 deletions Example/chap01/实例1/BoxLayoutFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//BoxLayoutFrame.java
import java.awt.*;
import javax.swing.*;

public class BoxLayoutFrame extends JFrame {
BoxLayoutTest panel = new BoxLayoutTest();

public BoxLayoutFrame() {
this.getContentPane().add(panel);
this.setSize(500,220);
this.setTitle("BoxLayoutDemo");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.show();
}

public static void main(String[] args) {
BoxLayoutFrame frame = new BoxLayoutFrame();
}
}

class BoxLayoutTest extends JPanel {
BoxLayoutTest() {
// Set the layout to a y-axis BoxLayout
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

// Create three components
TextField textField = new TextField();
TextArea textArea = new TextArea(4, 20);
JButton button = new JButton(
"Click me!");

// Add the three components to the BoxLayout
add(new JLabel("TextField"));
add(textField);
add(new JLabel("TextArea"));
add(textArea);
add(new JLabel("Button"));
add(button);
}
}
Binary file added Example/chap01/实例1/CardLayoutFrame.class
Binary file not shown.
59 changes: 59 additions & 0 deletions Example/chap01/实例1/CardLayoutFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//CardLayoutFrame.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class CardLayoutFrame extends JFrame {
JButton btPrevious = new JButton("前一张");
JButton btNext = new JButton("下一张");
JPanel flowPanel = new JPanel(new FlowLayout());
JPanel cardPanel = new JPanel(new CardLayout());
int currentIndex = 0;

public CardLayoutFrame() {
this.getContentPane().add(flowPanel,BorderLayout.SOUTH);
this.getContentPane().add(cardPanel,BorderLayout.CENTER);
cardPanel.add(getCard(1),"Card1");
cardPanel.add(getCard(2),"Card2");
flowPanel.add(btPrevious);
flowPanel.add(btNext);
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
switchCard();
}
};
btPrevious.addActionListener(listener);
btNext.addActionListener(listener);

this.setSize(300,200);
this.setTitle("GardLayoutDemo");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.show();
}

JPanel getCard(int index){
JPanel panel = new JPanel(new BorderLayout());
JLabel label = new JLabel("<HTML><h1 style=color:red>"+
"这是第"+index+"张卡片"+
"</h1></HTML>"
);
label.setHorizontalAlignment(JLabel.CENTER);
panel.add(label);
return panel;
}

void switchCard(){
CardLayout cl = (CardLayout)cardPanel.getLayout();
if (currentIndex==0){
currentIndex++;
cl.show(cardPanel,"Card2");
}else{
currentIndex--;
cl.show(cardPanel,"Card1");
}
}

public static void main(String[] args) {
CardLayoutFrame frame = new CardLayoutFrame();
}
}
Binary file added Example/chap01/实例1/FlowLayoutDemo.class
Binary file not shown.
51 changes: 51 additions & 0 deletions Example/chap01/实例1/FlowLayoutDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class FlowLayoutDemo extends Applet implements ItemListener
{
String msg="";
Checkbox Win98, WinNT,Linux, mac;

public void init()
{
setLayout(new FlowLayout(FlowLayout.LEFT));

Win98= new Checkbox("Win98",null,true);
WinNT = new Checkbox("Win NT/2000");
Linux = new Checkbox("Linux / Unix");
mac = new Checkbox("MacOS");

add(Win98);
add(WinNT);
add(Linux);
add(mac);

Win98.addItemListener(this);
WinNT.addItemListener(this);
Linux.addItemListener(this);
mac.addItemListener(this);
}

public void itemStateChanged(ItemEvent ie)
{
repaint();
}

public void paint(Graphics g)
{
msg="current state: ";
g.drawString(msg, 6, 80);
msg=" Window 98: "+Win98.getState();
g.drawString(msg, 6, 100);
msg=" Window NT / 2000: "+WinNT.getState();
g.drawString(msg, 6, 120);
msg=" Linux / Unix: "+Linux.getState();
g.drawString(msg, 6, 140);
msg=" MacOs "+mac.getState();
g.drawString(msg, 6, 160);


}

}
Binary file added Example/chap01/实例1/GridLayoutDemo.class
Binary file not shown.
21 changes: 21 additions & 0 deletions Example/chap01/实例1/GridLayoutDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.awt.*;
import java.applet.*;

public class GridLayoutDemo extends Applet
{
static final int n=4;
public void init()
{
setLayout(new GridLayout(n,n));
setFont(new Font("Times New Roman", Font.BOLD, 24));

for (int i=0; i<n; i++){
for(int j=0; j<n; j++)
{
int k=i*n+j;
if (k>0)
add(new Button(""+k));
}
}
}
}
Binary file added Example/chap01/实例1/LoginDialogDemo.class
Binary file not shown.
47 changes: 47 additions & 0 deletions Example/chap01/实例1/LoginDialogDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//LoginDialogDemo.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class LoginDialogDemo extends JFrame {
JButton button = new JButton("Click Me");
JPanel panel = new JPanel(new FlowLayout());

public LoginDialogDemo() {
final JFrame frame = this;
this.getContentPane().add(panel,BorderLayout.SOUTH);
panel.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showLoginDialog(frame);
}
});
this.setSize(300,200);
this.setTitle("ÏÔʾµÇ½¶Ô»°¿ò");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.show();
}

void showLoginDialog(JFrame frame){
JPanel p = new JPanel(new GridLayout(0,1));
JTextField tfUserName = new JTextField();
JPasswordField tfPassword = new JPasswordField();
p.add(new JLabel("Username: "));
p.add(tfUserName);
p.add(new JLabel("Password: "));
p.add(tfPassword);
if (JOptionPane.showConfirmDialog(frame // may want to pass your application frame here
,p
,"Login"
,JOptionPane.OK_CANCEL_OPTION
,JOptionPane.PLAIN_MESSAGE
) == JOptionPane.OK_OPTION) {
System.out.println("User Name:"+tfUserName.getText());
System.out.println("Password:" + new String(tfPassword.getPassword()));
}
}

public static void main(String[] args) {
LoginDialogDemo frame = new LoginDialogDemo();
}
}
5 changes: 5 additions & 0 deletions Example/chap01/实例1/TestApplet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<applet code="BorderLayoutDemo.class" height=200 width=300></applet>
</body>
</html>
Binary file added Example/chap01/实例10/FontDemo.class
Binary file not shown.
Loading

0 comments on commit ea842d5

Please sign in to comment.