?? easyadsl.java
字號:
package gongju;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextArea;
/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Easyadsl extends JFrame {
private JPanel jPanel1;
private JTextArea txtMSG;
private JScrollPane jScrollPane1;
private JButton btnLAND;
private JTextField txtPASSWD;
private JTextField txtNAME;
private JLabel labPASSWD;
private JLabel labNAME;
private Process process;
public Easyadsl() {
super("\u5feb\u901f\u62e8\u53f7");
init();
Exit();
}
public void init() {
{
jPanel1 = new JPanel();
getContentPane().add(jPanel1, BorderLayout.CENTER);
{
labNAME = new JLabel();
jPanel1.add(labNAME);
labNAME.setText("\u7528\u6237\u540d");
labNAME.setBounds(14, 14, 56, 28);
}
{
labPASSWD = new JLabel();
jPanel1.add(labPASSWD);
labPASSWD.setText("\u5bc6\u7801");
labPASSWD.setBounds(14, 49, 56, 28);
}
{
txtNAME = new JTextField();
jPanel1.add(txtNAME);
txtNAME.setBounds(77, 14, 133, 28);
}
{
txtPASSWD = new JTextField();
jPanel1.add(txtPASSWD);
txtPASSWD.setBounds(77, 49, 133, 28);
}
{
btnLAND = new JButton();
jPanel1.add(btnLAND);
btnLAND.setText("\u767b\u5f55");
btnLAND.setBounds(217, 35, 63, 28);
btnLAND.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
land();
}
});
}
{
jScrollPane1 = new JScrollPane();
jPanel1.add(jScrollPane1);
jScrollPane1.setBounds(0, 84, 294, 77);
{
txtMSG = new JTextArea();
jScrollPane1.setViewportView(txtMSG);
}
}
}
{
this.setSize(299, 204);
setVisible(true);
}
}
public void land() {
try {
txtMSG.setText("");
String name = txtNAME.getText();
String passwd = txtPASSWD.getText();
process = Runtime.getRuntime().exec(
"CMD /C RASDIAL ADSL " + name + " " + passwd); // 調用rasial指令來連接adsl
{
String msg;
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
while ((msg = bufferedReader.readLine()) != null) {
System.out.println(msg);
txtMSG.append(msg + "\n");
}
// 執行錯誤命令時
{
String errmsg;
BufferedReader err_bufferedReader = new BufferedReader(
new InputStreamReader(process.getErrorStream()));
while ((errmsg = err_bufferedReader.readLine()) != null) {
System.out.println(errmsg);
txtMSG.append(errmsg + "\n");
}
}
}
process.destroy();
} catch (Exception ex) {
process.destroy();
ex.printStackTrace();
}
}
public void Exit() {
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
// 結束進程
if (process != null)
process.destroy();
dispose();
}
});
}
/**
* @param args
*/
public static void main(String[] args) {
new Easyadsl();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -