-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit ea842d5
Showing
597 changed files
with
26,068 additions
and
0 deletions.
There are no files selected for viewing
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,4 @@ | ||
*.swp | ||
/Example/nbproject/private/ | ||
/Example/build/ | ||
/Example/dist/ |
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,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(); | ||
} | ||
} |
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,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()); | ||
} | ||
} | ||
} |
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 @@ | ||
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 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 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 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,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 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,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 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,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 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,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 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,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(); | ||
} | ||
} |
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,5 @@ | ||
<html> | ||
<body> | ||
<applet code="BorderLayoutDemo.class" height=200 width=300></applet> | ||
</body> | ||
</html> |
Binary file not shown.
Oops, something went wrong.