package feige;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.InetAddress;
import javax.swing.DebugGraphics;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class NeiRongJPanel extends JPanel {
private static final long serialVersionUID = 1L;
/*
* 这个类的做用是 创建一个panel 在里面加 上了一个多行和单行文本框
* 还 给按钮和弹出式书签加了 时间监听器
*/
private static JTextField textField; //单行文本
public static JTextArea textArea; //多行文本
private String hisIP;
private JButton btnqingkong; //清空的按钮
private final JButton btntuichu;//退出按钮
private final JButton btnfasong;//发送按钮
private final JPanel panel = new JPanel();//用于存放这几个按钮用的
final JCheckBox checkBox ,checkBox_1,checkBox_2;
private BtnMouseEvent btnEvnet =new BtnMouseEvent();//对这几个按钮的鼠标和动作事件
private LabMouseEvent labEvent =new LabMouseEvent();//选文件那个书签 的 鼠标事件
private BoxActionEvent boxEvent =new BoxActionEvent();// 复选框 的 动作事件
private ThisKeyEvent keyEvent =new ThisKeyEvent();
public NeiRongJPanel() {
setLayout(new BorderLayout());
//设置了6行1列的方式存放按钮和书签 共放了5个 下面依次是存放顺序
panel.setLayout(new GridLayout(6, 1));
panel.setOpaque(false);
add(panel, BorderLayout.EAST);
//第一个按钮 1
btnfasong = new JButton();
btnfasong.setText(" 发送 ");
btnfasong.addActionListener(btnEvnet);
btnfasong.addMouseListener(btnEvnet);
panel.add(btnfasong);
//第一个书签 2
final JLabel label = new JLabel();
panel.add(label);
//第二个按钮 3
btnqingkong = new JButton();
btnqingkong.setText(" 清空 ");
btnqingkong.addActionListener(btnEvnet);
btnqingkong.addMouseListener(btnEvnet);
panel.add(btnqingkong);
//第二个书签 4
final JLabel label_2 = new JLabel();
panel.add(label_2);
//第三个按钮 5
btntuichu = new JButton();
panel.add(btntuichu);
btntuichu.setText(" 退出 ");
btntuichu.addActionListener(btnEvnet);
btntuichu.addMouseListener(btnEvnet);
//添加键盘事件
btnqingkong.addKeyListener(keyEvent);
btntuichu.addKeyListener(keyEvent);
btnfasong.addKeyListener(keyEvent);
//放下了三个panel 于又边放按钮的 panel 同一级
final JPanel panel_1 = new JPanel();
panel_1.setOpaque(false);
panel_1.setLayout(new BorderLayout());
panel_1.setDebugGraphicsOptions(DebugGraphics.NONE_OPTION);
add(panel_1);
setOpaque(false);
//滚动条的PANEL 用于放 多行文本
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setOpaque(false);
panel_1.add(scrollPane);
textArea = new JTextArea();
textArea.setWrapStyleWord(true);
textArea.setEditable(false);
textArea.setBackground(Color.WHITE);
textArea.setLineWrap(true);
textArea.setDisabledTextColor(Color.WHITE);
textArea.setColumns(30);
textArea.setSelectionColor(new Color(135, 206, 250));
textArea.setSelectedTextColor(Color.WHITE);
textArea.setForeground(new Color(30, 144, 255));
textArea.addKeyListener(keyEvent);
scrollPane.setViewportView(textArea);
// 存放一个单行文本框 和两个标签 其中一个可以弹出选择文件对话框
final JPanel panel_2 = new JPanel();
panel_2.setOpaque(false);
panel_1.add(panel_2, BorderLayout.NORTH);
//显示文件路径 用的标签
final JLabel lablujin = new JLabel();
lablujin.setForeground(Color.WHITE);
lablujin.setFont(new Font("", Font.BOLD, 14));
lablujin.setText("文件路径:");
panel_2.add(lablujin);
//单行文本的设置
textField = new JTextField();
textField.setForeground(Color.WHITE);
textField.setOpaque(false);
textField.setSelectionColor(new Color(135, 206, 250));
textField.setSelectedTextColor(Color.WHITE);
textField.setColumns(20);
textField.addKeyListener(keyEvent);
panel_2.add(textField);
//用于弹出文件选择框的 标签
final JLabel labchfile = new JLabel();
labchfile.setForeground(new Color(255, 0, 0));
labchfile.setText(" Open");
labchfile.addMouseListener(labEvent);
panel_2.add(labchfile);
//放复选框用的 容器panel
final JPanel panel_3 = new JPanel();
panel_3.setOpaque(false);
panel_1.add(panel_3, BorderLayout.SOUTH);
// 第一个复选框
checkBox = new JCheckBox();
checkBox.setFont(new Font("新宋体", Font.PLAIN, 12));
checkBox.setText("1");
checkBox.setForeground(Color.WHITE);
checkBox.setPreferredSize(new Dimension(80, 13));
checkBox.addActionListener(boxEvent);
checkBox.setOpaque(false);
panel_3.add(checkBox);
// 第二个复选框
checkBox_1 = new JCheckBox();
checkBox_1.setFont(new Font("新宋体", Font.PLAIN, 12));
checkBox_1.setForeground(new Color(255, 250, 240));
checkBox_1.setPreferredSize(new Dimension(160, 13));
checkBox_1.addActionListener(boxEvent);
checkBox_1.setOpaque(false);
checkBox_1.setText("手动设置远程主机地址");
panel_3.add(checkBox_1);
//第三个复选框
checkBox_2 = new JCheckBox("播放音乐",true);
checkBox_2.setFont(new Font("新宋体", Font.PLAIN, 12));
checkBox_2.setForeground(Color.BLUE);
checkBox_2.setPreferredSize(new Dimension(80, 13));
checkBox_2.addActionListener(boxEvent);
checkBox_2.setOpaque(false);
panel_3.add(checkBox_2);
//起站空位作用 west
final JPanel panel_4 = new JPanel();
panel_4.setOpaque(false);
panel_1.add(panel_4, BorderLayout.WEST);
}
public static void setServerIPToText(String[] s)
{
for(int i=0;i<s.length;i++)
{
textArea.append(s[i]);
textArea.append("\n");
}
}
// 掉用主窗口中的弹出 文件选择对话框
public static void popDialog()
{
AudioPlayerPanel au= AudioPlayerPanel.getAudioPlayer();
au.play("feige/labchoice.wav");
String filepath=PopDialog.getPopDialogClass().showChoiceDialog();
if(filepath!=null)
textField.setText(filepath);
au.stop();
au=null;
}
public void fasong()
{
TableJPanel tab=new TableJPanel();
if(tab.getSelectedRow()==-1)
{
JOptionPane.showMessageDialog(JieMian.frm, "请选择要传送的主机!\n在以上的表格中选定。");
return;
}
else {
String[][] data=Data.getDataClass().getSeverMeg();
hisIP=data[tab.getSelectedRow()-1][2];
}
if(hisIP==null)
{
JOptionPane.showMessageDialog(JieMian.frm, "远程主机IP为空!");
return;
}
String filetext=textField.getText();
if(filetext.equals("")||filetext.equals("请先选择文件"))
{
JOptionPane.showMessageDialog(JieMian.frm, "请先选择要发送的文件!");
return;
}
else{
final FileClient filesend =new FileClient();
filesend.setFileOpenPath(textField.getText());
filesend.setServerIP(hisIP);
filesend.fileSending();
filesend.close();
}
}
//按钮的动作事件 和 鼠标事件
class BtnMouseEvent extends MouseAdapter implements ActionListener
{
JButton btnA;
JButton btnM;
int sum=0;
public void actionPerformed(ActionEvent e)
{
btnA=(JButton)e.getSource();
if(sum<20)
{
AudioPlayerPanel au= AudioPlayerPanel.getAudioPlayer();
au.play("feige/btndown.wav");
}
if(btnA==btntuichu)
{
System.exit(0);
}
else if(btnM==btnfasong)
{
// 发送后的动作
fasong();
}
else if(btnM==btnqingkong)
{
textArea.setText(null);
}
}
public void mouseEntered(MouseEvent e)
{
btnM=(JButton)e.getSource();
btnM.setFont(new Font("", Font.LAYOUT_N