package com.smu.yyh.ssh;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.border.StandardBorderPainter;
import org.jvnet.substance.button.ClassicButtonShaper;
import org.jvnet.substance.painter.StandardGradientPainter;
import org.jvnet.substance.skin.EmeraldDuskSkin;
import org.jvnet.substance.theme.SubstanceTerracottaTheme;
import org.jvnet.substance.watermark.SubstanceBubblesWatermark;
import ch.ethz.ssh2.KnownHosts;
import com.smu.yyh.conn.ConnectionThread;
/**
* 主程序入口(登录页)
*
* @author yyh
*
*/
public class SecureShell {
private static final String knownHostPath = "~/.ssh/known_hosts";
private JFrame loginFrame = null;
private JLabel hostLabel;
private JLabel userLabel;
private JTextField hostField;
private JTextField userField;
private JButton loginButton;
private KnownHosts database = new KnownHosts();
public SecureShell() {
File knownHostFile = new File(knownHostPath);
if (knownHostFile.exists()) {
try {
database.addHostkeys(knownHostFile);
} catch (IOException e) {
}
}
}
void loginPressed() {
String hostname = hostField.getText().trim();
String username = userField.getText().trim();
if ((hostname.length() == 0) || (username.length() == 0)) {
JOptionPane.showMessageDialog(loginFrame, "请填写IP以及用户名");
return;
}
loginButton.setEnabled(false);
hostField.setEnabled(false);
userField.setEnabled(false);
ConnectionThread ct = new ConnectionThread(hostname, username, database, loginFrame);
ct.start();
}
void showGUI() {
Dimension scrnsize = Toolkit.getDefaultToolkit().getScreenSize();
loginFrame = new JFrame("SSH远程连接");
loginFrame.setSize(270, 200);
loginFrame.setLocation(scrnsize.width / 2 - loginFrame.getWidth() / 2, scrnsize.height / 2 - loginFrame.getHeight() / 2);
hostLabel = new JLabel("HostName:");
userLabel = new JLabel("UserName:");
hostField = new JTextField("", 20);
userField = new JTextField("", 10);
loginButton = new JButton("连接");
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
loginPressed();
}
});
JPanel loginPanel = new JPanel();
loginPanel.setBorder(BorderFactory.createTitledBorder("连接信息"));
loginPanel.setLayout(null);
loginPanel.setSize(200,150);
loginPanel.setLocation(30, 60);
hostLabel.setBounds(20, 40, 100, 25);
hostLabel.setFont(new Font("Courier",Font.PLAIN,16));
loginPanel.add(hostLabel);
hostField.setBounds(110, 40, 130, 25);
loginPanel.add(hostField);
userLabel.setBounds(20, 70, 100, 25);
userLabel.setFont(new Font("Courier",Font.PLAIN,16));
loginPanel.add(userLabel);
userField.setBounds(110, 70, 130, 25);
loginPanel.add(userField);
loginButton.setBounds(95, 110, 80, 30);
loginPanel.add(loginButton);
loginFrame.getRootPane().setDefaultButton(loginButton);
loginFrame.getContentPane().add(loginPanel);
loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loginFrame.setResizable(false);
loginFrame.setLocationRelativeTo(null);
loginFrame.setVisible(true);
}
void startGUI() {
Runnable r = new Runnable() {
public void run() {
showGUI();
}
};
SwingUtilities.invokeLater(r);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(new SubstanceLookAndFeel());
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
SubstanceLookAndFeel.setCurrentTheme(new SubstanceTerracottaTheme());
SubstanceLookAndFeel.setSkin(new EmeraldDuskSkin());
SubstanceLookAndFeel.setCurrentButtonShaper(new ClassicButtonShaper());
SubstanceLookAndFeel.setCurrentWatermark(new SubstanceBubblesWatermark());
SubstanceLookAndFeel.setCurrentBorderPainter(new StandardBorderPainter());
SubstanceLookAndFeel.setCurrentGradientPainter(new StandardGradientPainter());
SubstanceLookAndFeel.setCurrentTitlePainter(new String());
} catch (Exception e) {
e.printStackTrace();
}
SecureShell client = new SecureShell();
client.startGUI();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SSH.rar (24个子文件)
SSH
bin
com
smu
yyh
conn
ConnectionThread.class 5KB
ConnectionThread$1.class 757B
dialog
TerminalDialog$RemoteConsumer.class 2KB
EnterSomethingDialog$1.class 905B
TerminalDialog.class 3KB
TerminalDialog$1.class 817B
TerminalDialog$2.class 1KB
EnterSomethingDialog.class 3KB
utils
AdvancedVerifier.class 3KB
InteractiveLogic.class 2KB
ssh
SecureShell$1.class 731B
SecureShell.class 6KB
SecureShell$2.class 625B
.settings
org.eclipse.jdt.core.prefs 598B
src
com
smu
yyh
conn
ConnectionThread.java 4KB
dialog
TerminalDialog.java 4KB
EnterSomethingDialog.java 2KB
utils
AdvancedVerifier.java 2KB
InteractiveLogic.java 1KB
ssh
SecureShell.java 5KB
.project 379B
.classpath 425B
lib
ganymed-ssh2-build210.jar 239KB
substance.jar 1.66MB
共 24 条
- 1
资源评论
- role1002015-10-30很不错,有借鉴价值
- Moooosi2019-03-31可以,但是无法执行实时输出的命令,例如iotop
- jsjhtcl0082017-10-17资源有价值
- funan2019-08-31不错,是我想要的
- Fly8723652015-05-25东西可用,但是还得自己再改造!
LeBron_Six
- 粉丝: 802
- 资源: 208
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功