📄 hideinfopanel.java
字号:
package hideInfo;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.*;
//窗口中的主Panel ,处理所有消息、安放所有按钮等控件
public class HideInfoPanel extends JPanel implements ActionListener
{
private boolean isHideMode; //两种模式:隐藏模式和提取模式, true代表隐藏模式
private MediaTracker mt; //用于监控多媒体对象的类
private JFileChooser jfc; //文件选择器
private Image im; //图像对象
private JButton bFile1; //按钮:选择源图像 左上第一个按钮
private JButton bFile2; //按钮:选择源文本文件 左上第二
private JButton bFile3; //按钮:选择目的图像: 左上第三
private JButton bMode; //模式切换按钮:左下按钮
private JButton bOp; //启动操作(在隐藏模式下启动隐藏操作,提取模式下提取操作)
private File originBMP; //源图像文件对象
private File targetBMP; //目的图像文件对象
private File originTxt; //源文本文件对象
private File targetTxt; //目的文本文件对象
private BMP originImage; //第三方类:我借用进来的 用于直接把BMP文件转换为Image对象,因为JAVA不直接支持载入BMP文件。隐藏和提取时不用它,因为直接把BMP文件当作文件来处理,不需要转换为Image对象
JLabel tag1,tag2,tag3; //三个显示“路径”字样的标签
JLabel status; //最下方提示栏
JTextField pathFile1,pathFile2,pathFile3; //显示上面三个文件的路径 在Panel的右上方
//JLabel tag5,tag4;
ShowPanel show1,show2; //显示两个BMP图像 (Panel的右下)
public HideInfoPanel()
{
//初始化
this.isHideMode=true; //默认隐藏模式
this.setLayout(null); //使用坐标方式指定各个按钮的位置
this.mt=new MediaTracker(this);
jfc=new JFileChooser(); //文件选择器
this.im=Toolkit.getDefaultToolkit().getImage("resource/background.jpg");//载入背景
mt.addImage(this.im,1);
try
{
mt.waitForID(1);//跟踪多媒体文件
}
catch (InterruptedException e)
{
}
this.setVisible(true);
this.bFile1=new JButton("选择原图像文件"); //显示的字样 (按钮)
this.bFile1.setBounds(70,75,120,35); //位置和大小
this.bFile1.setFont(new Font("宋体",Font.PLAIN,12));//字体
this.bFile1.setOpaque(false); //透明
this.bFile1.setForeground(new Color(117,60,27)); //字体颜色
//this.bFile1.setBorder(null);
this.bFile1.addActionListener(this); //如果这个按钮被按动,事件将被发送到本累下面的处理函数中
this.add(bFile1);
this.bFile2=new JButton("选择待隐藏文本");//同上
this.bFile2.setBounds(70,120,120,35);
this.bFile2.setFont(new Font("宋体",Font.PLAIN,12));
this.bFile2.setOpaque(false);
this.bFile2.setForeground(new Color(117,60,27));
//this.bFile2.setBorder(null);
this.bFile2.addActionListener(this);
this.add(bFile2);
this.bFile3=new JButton("选择目标图像");
this.bFile3.setBounds(70,165,120,35);
this.bFile3.setFont(new Font("宋体",Font.PLAIN,12));
this.bFile3.setOpaque(false);
this.bFile3.setForeground(new Color(117,60,27));
//this.bFile3.setBorder(null);
this.bFile3.addActionListener(this);
this.add(bFile3);
this.bOp=new JButton("开始隐藏操作");
this.bOp.setBounds(70,220,120,100);
this.bOp.setFont(new Font("宋体",Font.BOLD,12));
this.bOp.setOpaque(false);
this.bOp.setForeground(new Color(117,60,27));
this.bOp.addActionListener(this);
this.add(bOp);
this.bMode=new JButton("切换模式");
this.bMode.setBounds(70,340,120,80);
this.bMode.setFont(new Font("宋体",Font.BOLD,12));
this.bMode.setOpaque(false);
this.bMode.setForeground(new Color(117,60,27));
//this.bMode.setBorder(null);
this.bMode.addActionListener(this);
this.add(bMode);
this.tag1=new JLabel("路径:");
this.tag1.setBounds(200,75,40,35);
this.tag1.setFont(new Font("宋体",Font.PLAIN,14));
// this.tag1.setHorizontalAlignment(SwingConstants.RIGHT);
this.tag1.setForeground(new Color(117,60,27));
this.add(this.tag1);
this.tag2=new JLabel("路径:");
this.tag2.setBounds(200,120,40,35);
this.tag2.setFont(new Font("宋体",Font.PLAIN,14));
// this.tag2.setHorizontalAlignment(SwingConstants.RIGHT);
this.tag2.setForeground(new Color(117,60,27));
this.add(this.tag2);
this.tag3=new JLabel("路径:");
this.tag3.setBounds(200,165,40,35);
this.tag3.setFont(new Font("宋体",Font.PLAIN,14));
// this.tag3.setHorizontalAlignment(SwingConstants.RIGHT);
this.tag3.setForeground(new Color(117,60,27));
this.add(this.tag3);
// this.tag4=new JLabel("隐藏操作前:");
// this.tag4.setBounds(270,210,200,25);
// this.tag4.setHorizontalAlignment(SwingConstants.LEFT);
// this.tag4.setFont(new Font("宋体",Font.PLAIN,12));
// this.tag4.setForeground(new Color(117,60,27));
// this.add(this.tag4);
//
// this.tag5=new JLabel("隐藏操作后:");
// this.tag5.setBounds(500,210,200,25);
// this.tag5.setFont(new Font("宋体",Font.PLAIN,12));
// this.tag5.setForeground(new Color(117,60,27));
// this.tag5.setHorizontalAlignment(SwingConstants.LEFT);
// this.add(this.tag5);
this.status=new JLabel("当前模式:信息隐藏模式");
this.status.setBounds(70,450,680,30);
this.status.setHorizontalAlignment(SwingConstants.LEFT); //左对齐
this.status.setFont(new Font("宋体",Font.ITALIC,16));
this.status.setForeground(Color.YELLOW);
this.status.setOpaque(false);
this.add(this.status);
this.pathFile1=new JTextField(100);
this.pathFile1.setBounds(240,75,490,35);
this.pathFile1.setFont(new Font("宋体",Font.PLAIN,12));
this.pathFile1.setEditable(false);
this.pathFile1.setOpaque(false);
this.pathFile1.setBorder(null);
this.add(this.pathFile1);
this.pathFile2=new JTextField(100);
this.pathFile2.setBounds(240,120,490,35);
this.pathFile2.setFont(new Font("宋体",Font.PLAIN,12));
this.pathFile2.setEditable(false);
this.pathFile2.setOpaque(false);
this.pathFile2.setBorder(null);
this.add(this.pathFile2);
this.pathFile3=new JTextField(100);
this.pathFile3.setBounds(240,165,490,35);
this.pathFile3.setFont(new Font("宋体",Font.PLAIN,12));
this.pathFile3.setEditable(false);
this.pathFile3.setOpaque(false);
this.pathFile3.setBorder(null);
this.add(this.pathFile3);
this.show1=new ShowPanel();
this.show1.setBorder(new TitledBorder(new LineBorder(new Color(69,167,116)),"隐藏前的图像",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.DEFAULT_POSITION,new Font("宋体",Font.PLAIN,12),new Color(117,60,27)));
this.show1.setBounds(220,200,230,230);
// this.show1.setBackground(Color.WHITE);
this.show1.setOpaque(false);
this.add(this.show1);
// show1.setImage(Toolkit.getDefaultToolkit().getImage("resource/dd.JPG"));
show1.repaint();
this.show2=new ShowPanel();
this.show2.setBorder(new TitledBorder(new LineBorder(new Color(69,167,116)),"隐藏后的图像",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.DEFAULT_POSITION,new Font("宋体",Font.PLAIN,12),new Color(117,60,27))); //带有标题的边框
this.show2.setBounds(480,200,230,230);
// this.show2.setBackground(Color.WHITE);
this.show2.setOpaque(false);
this.add(this.show2);
// show2.setImage(Toolkit.getDefaultToolkit().getImage("resource/dd.JPG"));
show2.repaint();
this.repaint();
}
public void actionPerformed(ActionEvent e) {//这个函数负责处理所有按钮被按动所产生的事件
if(((JButton)e.getSource()).equals(this.bFile1)) //按动的按钮是选择源图像文件按钮
{
int retVal=jfc.showOpenDialog(this); //打开文件选择器
if (retVal==JFileChooser.APPROVE_OPTION)
{
this.originBMP=jfc.getSelectedFile();//选定文件
// System.out.println("File name is : " +this.originBMP.getAbsolutePath());
this.pathFile1.setText(this.originBMP.getAbsolutePath());//显示它的路径
if(this.originBMP.getName().endsWith(".BMP")||this.originBMP.getName().endsWith(".bmp"))
{//如果是.bmp文件 则显示它
this.originImage=new BMP(this.originBMP);
this.show1.setImage(this.originImage.getImage());
this.show1.repaint();
this.status.setText("源图像文件大小:"+this.originBMP.length()+" Byte");
}
else
{
//否则在状态栏显示错误信息
this.status.setText("提示:源图像文件不是BMP格式,请重新指定");
this.show1.setImage(null);
this.originBMP=null;
this.show1.repaint();
}
this.repaint();
}
else this.originBMP=null;
}
if(((JButton)e.getSource()).equals(this.bFile2)) //按下的是第二个按钮 选择文本
{
int retVal=jfc.showOpenDialog(this);
if(this.isHideMode)//判断是不是隐藏模式 两个模式下文本文件的作用不痛
{
if (retVal==JFileChooser.APPROVE_OPTION)
{
this.originTxt=jfc.getSelectedFile();
this.pathFile2.setText(this.originTxt.getAbsolutePath());
this.status.setText("待隐藏文件大小:"+this.originTxt.length()+" Byte");
}
else this.originTxt=null;
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -