- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道了确切的问题所在。当我在 Steganography_Controller 构造函数中调用 FileTransfer 方法时,窗口会挂起。当我评论方法调用时,代码工作正常。这是一个工作代码。
这是我的 Steganography_Controller 类
public class Steganography_Controller {
// Program Variables
private Steganography_View view;
// Panel Displays
private JPanel decode_panel;
private JPanel encode_panel;
// Panel Variables
private JTextArea input;
private JButton encodeButton, decodeButton;
private JLabel image_input;
// Menu Variables
private JMenuItem encode;
private JMenuItem decode;
private JMenuItem sendfile;
private JMenuItem calculatepsnr;
private JMenuItem exit;
// action event classes
private Encode enc;
private Decode dec;
/*private SendFile send;
private CalculatePSNR psnr;*/
private EncodeButton encButton;
private DecodeButton decButton;
// decode variable
private String stat_path = "";
private String stat_name = "";
// encode variable
private String stegan = "";
private String path = "";
/*
* Constructor to initialize view, model and environment variables
*
* @param aView A GUI class, to be saved as view
*
* @param aModel A model class, to be saved as model
*/
public Steganography_Controller(Steganography_View aView) {
// program variables
view = aView;
//model = aModel;
// assign View Variables
// 2 views
encode_panel = view.getTextPanel();
decode_panel = view.getImagePanel();
// 2 data options
input = view.getText();
image_input = view.getImageInput();
// 2 buttons
encodeButton = view.getEButton();
decodeButton = view.getDButton();
// menu
encode = view.getEncode();
decode = view.getDecode();
sendfile = view.getSendFile();
calculatepsnr = view.getPSNR();
exit = view.getExit();
// assign action events
enc = new Encode();
encode.addActionListener(enc);
dec = new Decode();
decode.addActionListener(dec);
/*send = new SendFile();
sendfile.addActionListener(send);
psnr = new CalculatePSNR();
calculatepsnr.addActionListener(psnr);*/
exit.addActionListener(new Exit());
encButton = new EncodeButton();
encodeButton.addActionListener(encButton);
decButton = new DecodeButton();
decodeButton.addActionListener(decButton);
// encode view as default
encode_view();
FileTransfer(); /* <----- Here's what hangs the code.Maybe because i am using socket connection but would like to know the exact problem and solutions if any.*/
}
/*
* Updates the single panel to display the Encode View.
*/
private void encode_view() {
update();
view.setContentPane(encode_panel);
view.setVisible(true);
}
/*
* Updates the single panel to display the Decode View.
*/
private void decode_view() {
update();
view.setContentPane(decode_panel);
view.setVisible(true);
}
/*
* Encode Class - handles the Encode menu item
*/
private class Encode implements ActionListener {
/*
* handles the click event
*
* @param e The ActionEvent Object
*/
public void actionPerformed(ActionEvent e) {
encode_view(); // show the encode view
}
}
/*
* Decode Class - handles the Decode menu item
*/
private class Decode implements ActionListener {
/*
* handles the click event
*
* @param e The ActionEvent Object
*/
public void actionPerformed(ActionEvent e) {
decode_view(); // show the decode view
// start path of displayed File Chooser
}
}
/*
* Exit Class - handles the Exit menu item
*/
private class Exit implements ActionListener {
/*
* handles the click event
*
* @param e The ActionEvent Object
*/
public void actionPerformed(ActionEvent e) {
System.exit(0); // exit the program
}
}
/*
* Encode Button Class - handles the Encode Button item
*/
private class EncodeButton implements ActionListener {
/*
* handles the click event
*
* @param e The ActionEvent Object
*/
public void actionPerformed(ActionEvent e) {
}
}
/*
* Decode Button Class - handles the Decode Button item
*/
private class DecodeButton implements ActionListener {
/*
* handles the click event
*
* @param e The ActionEvent Object
*/
public void actionPerformed(ActionEvent e) {
}
}
/*
* Listens to incoming socket connections and receives file
*/
public void FileTransfer() {
try {
System.out.println("Server running...");
/* Listen on port 1111 */
ServerSocket server = new ServerSocket(1111);
/* Accept the sk */
while (true) {
Socket sk = server.accept();
System.out.println("Server accepted client");
InputStream input = sk.getInputStream();
BufferedReader inBuf = new BufferedReader(
new InputStreamReader(sk.getInputStream()));
BufferedWriter outBuf = new BufferedWriter(
new OutputStreamWriter(sk.getOutputStream()));
/* Read the filename */
String filename = inBuf.readLine();
if (!filename.equals("")) {
/* Reply back to client with READY status */
outBuf.write("READY\n");
outBuf.flush();
}
// System.out.println("\nfilename:"+filename);
/* Create a new file in the tmp directory using the filename */
String workingDir = System.getProperty("user.dir");
// System.out.println("Working Dir:"+workingDir);
String path = workingDir + "\\images\\" + filename;
System.out.println("serverpath:" + path);
int filesize = 2022386;
int bytesRead;
int currentTot = 0;
byte[] bytearray = new byte[filesize];
FileOutputStream fos = new FileOutputStream(new File(path));
BufferedOutputStream bos = new BufferedOutputStream(fos);
bytesRead = input.read(bytearray, 0, bytearray.length);
currentTot = bytesRead;
do {
bytesRead = input.read(bytearray, currentTot,
(bytearray.length - currentTot));
if (bytesRead >= 0)
currentTot += bytesRead;
} while (bytesRead > -1);
bos.write(bytearray, 0, currentTot);
// System.out.println("BYteRECEive:"+bytesReceived);
input.close();
fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void update() {
input.setText(""); // clear textarea
image_input.setIcon(null); // clear image
stat_path = ""; // clear path
stat_name = ""; // clear name
}
/*
* Main Method for testing
*/
/*public static void main(String args[]) {
new Steganography_Controller(new Steganography_View("Steganography"),
new Steganography());
}*/
}
这是登录类
public class Login extends JDialog {
private JTextField tfUsername;
private JPasswordField tfPassword;
private JLabel lbUsername;
private JLabel lbPassword;
private JButton btnLogin;
private JButton btnCancel;
private JButton btnRegister;
private boolean succeeded;
// Steganography_Controller controller;
final static JFrame frame = new JFrame("JDialog Demo");
public Login(Frame parent) {
super(parent, "Login", true);
JDialog dialog = new JDialog();
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints cs = new GridBagConstraints();
cs.fill = GridBagConstraints.HORIZONTAL;
lbUsername = new JLabel("Username: ");
cs.gridx = 0;
cs.gridy = 0;
cs.gridwidth = 1;
panel.add(lbUsername, cs);
tfUsername = new JTextField(20);
cs.gridx = 1;
cs.gridy = 0;
cs.gridwidth = 2;
panel.add(tfUsername, cs);
lbPassword = new JLabel("Password: ");
cs.gridx = 0;
cs.gridy = 1;
cs.gridwidth = 1;
panel.add(lbPassword, cs);
tfPassword = new JPasswordField(20);
cs.gridx = 1;
cs.gridy = 1;
cs.gridwidth = 2;
panel.add(tfPassword, cs);
panel.setBorder(new LineBorder(Color.GRAY));
btnLogin = new JButton("Login");
btnLogin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(Login.this,
"Hi ! You have successfully logged in.",
"Login", JOptionPane.INFORMATION_MESSAGE);
dispose();
//Here i need to open my new frame
new Steganography_Controller(new
Steganography_View("Steganography")
);
}
});
JPanel bp = new JPanel();
bp.add(btnLogin);
getContentPane().add(panel, BorderLayout.CENTER);
getContentPane().add(bp, BorderLayout.PAGE_END);
pack();
setResizable(false);
setLocationRelativeTo(parent);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
// setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
}
public String getUsername() {
return tfUsername.getText().trim();
}
public String getPassword() {
return new String(tfPassword.getPassword());
}
public boolean isSucceeded() {
return succeeded;
}
public static void main(String args[]) {
Login l = new Login(frame);
l.setVisible(true);
}
}
这是 Steganography_View
public class Steganography_View extends JFrame
{
//size variables for window
private static int WIDTH = 500;
private static int HEIGHT = 400;
//elements for JPanel
private JTextArea input;
//private JScrollBar scroll,scroll2;
private JButton encodeButton,decodeButton;
private JLabel image_input;
//elements for Menu
private JMenu file;
private JMenuItem encode;
private JMenuItem decode;
private JMenuItem sendfile;
private JMenuItem calculatepsnr;
private JMenuItem exit;
/*
*Constructor for Steganography_View class
*@param name Used to set the title on the JFrame
*/
public Steganography_View(String name)
{
//set the title of the JFrame
super(name);
//Menubar
JMenuBar menu = new JMenuBar();
file = new JMenu("File"); file.setMnemonic('F');
encode = new JMenuItem("Encode"); encode.setMnemonic('E'); file.add(encode);
decode = new JMenuItem("Decode"); decode.setMnemonic('D'); file.add(decode);
sendfile = new JMenuItem("Send File"); sendfile.setMnemonic('S'); file.add(sendfile);
calculatepsnr = new JMenuItem("Calculate PSNR"); calculatepsnr.setMnemonic('P'); file.add(calculatepsnr);
file.addSeparator();
exit = new JMenuItem("Exit"); exit.setMnemonic('x'); file.add(exit);
menu.add(file);
setJMenuBar(menu);
// display rules
setResizable(true); //allow window to be resized: true?false
setBackground(Color.lightGray); //background color of window: Color(int,int,int) or Color.name
setLocation(100,100); //location on the screen to display window
setDefaultCloseOperation(EXIT_ON_CLOSE);//what to do on close operation: exit, do_nothing, etc
setSize(WIDTH,HEIGHT); //set the size of the window
setVisible(true); //show the window: true?false
System.out.println("inside steganography_view");
}
/*
*@return The menu item 'Encode'
*/
public JMenuItem getEncode() { return encode; }
/*
*@return The menu item 'Send File'
*/
public JMenuItem getSendFile() { return sendfile; }
/*
*@return The menu item 'Decode'
*/
public JMenuItem getDecode() { return decode; }
/*
*@return The menu item 'Calculate PSNR'
*/
public JMenuItem getPSNR() { return calculatepsnr; }
/*
*@return The menu item 'Exit'
*/
public JMenuItem getExit() { return exit; }
/*
*@return The TextArea containing the text to encode
*/
public JTextArea getText() { return input; }
/*
*@return The JLabel containing the image to decode text from
*/
public JLabel getImageInput() { return image_input; }
/*
*@return The JPanel displaying the Encode View
*/
public JPanel getTextPanel() { return new Text_Panel(); }
/*
*@return The JPanel displaying the Decode View
*/
public JPanel getImagePanel() { return new Image_Panel(); }
/*
*@return The Encode button
*/
public JButton getEButton() { return encodeButton; }
/*
*@return The Decode button
*/
public JButton getDButton() { return decodeButton; }
private class Text_Panel extends JPanel
{
/*
*Constructor to enter text to be encoded
*/
public Text_Panel()
{
//setup GridBagLayout
GridBagLayout layout = new GridBagLayout();
GridBagConstraints layoutConstraints = new GridBagConstraints();
setLayout(layout);
input = new JTextArea();
layoutConstraints.gridx = 0; layoutConstraints.gridy = 0;
layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.BOTH;
layoutConstraints.insets = new Insets(0,0,0,0);
layoutConstraints.anchor = GridBagConstraints.CENTER;
layoutConstraints.weightx = 1.0; layoutConstraints.weighty = 50.0;
JScrollPane scroll = new JScrollPane(input,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
layout.setConstraints(scroll,layoutConstraints);
scroll.setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
add(scroll);
encodeButton = new JButton("Encode Now");
layoutConstraints.gridx = 0; layoutConstraints.gridy = 1;
layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.BOTH;
layoutConstraints.insets = new Insets(0,-5,-5,-5);
layoutConstraints.anchor = GridBagConstraints.CENTER;
layoutConstraints.weightx = 1.0; layoutConstraints.weighty = 1.0;
layout.setConstraints(encodeButton,layoutConstraints);
add(encodeButton);
//set basic display
setBackground(Color.lightGray);
setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
}
}
/*
*Class Image_Panel
*/
private class Image_Panel extends JPanel
{
/*
*Constructor for displaying an image to be decoded
*/
public Image_Panel()
{
//setup GridBagLayout
GridBagLayout layout = new GridBagLayout();
GridBagConstraints layoutConstraints = new GridBagConstraints();
setLayout(layout);
image_input = new JLabel();
layoutConstraints.gridx = 0; layoutConstraints.gridy = 0;
layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.BOTH;
layoutConstraints.insets = new Insets(0,0,0,0);
layoutConstraints.anchor = GridBagConstraints.CENTER;
layoutConstraints.weightx = 1.0; layoutConstraints.weighty = 50.0;
JScrollPane scroll2 = new JScrollPane(image_input,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
layout.setConstraints(scroll2,layoutConstraints);
scroll2.setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
image_input.setHorizontalAlignment(JLabel.CENTER);
add(scroll2);
decodeButton = new JButton("Decode Now");
layoutConstraints.gridx = 0; layoutConstraints.gridy = 1;
layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1;
layoutConstraints.fill = GridBagConstraints.BOTH;
layoutConstraints.insets = new Insets(0,-5,-5,-5);
layoutConstraints.anchor = GridBagConstraints.CENTER;
layoutConstraints.weightx = 1.0; layoutConstraints.weighty = 1.0;
layout.setConstraints(decodeButton,layoutConstraints);
add(decodeButton);
//set basic display
setBackground(Color.lightGray);
setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
}
}
最佳答案
它挂起的原因是因为当前线程正在监听传入连接(在事件调度线程中完成),从而阻塞。它不会立即返回,而是等待连接。因此,用于监听连接的代码应该位于其自己的线程中:
而不是 FileTransfer(); /* <----- Here's....*/
在自己的线程中运行它:
Thread fileTransferThread = new Thread(new Runnable(){
public void run(){
FileTransfer();
}
});
fileTransferThread.start();
关于java - 如何在单击按钮时打开框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22343268/
我在选项卡中有我的网络应用程序的选项。 aaa bbb ccc ddd eee 当用户单击任何选项卡(在同一窗口中)时,我会使用此代码获得淡出效果,然后自动
如何获得一个简单的调用单击来实现如下功能:http://jsfiddle.net/ftwPS/6/我显然错过了一些基本的东西,因为当您单击“CLICK”时这不起作用。 $('tr').click(fu
我有一个列表,在左侧显示一个插入符号图标,单击它时应该更改图标。每当我单击一个图标时,所有图标都会更改。 detailedInfo = []; subordinateInfo; openSu
我有一个 div,我想对其进行设置,以便当我单击其他内容时,它会隐藏该 div。 我也是这样 $('body').click(function(){ if(loginOpened) {
我有很多装有不同内容的盒子。 如果单击第一个框,您可以看到一个包含更多详细信息的弹出框。如果单击第二个、第三个等框,您必须查看这些框的详细信息。 我的问题:如果我点击框号。 2 我看到了盒子号的详细信
当我点击 .add-btn 时,我将 .add-btn 的样式更改为 background:#cccccc 并将 val() 更改为“-”。 现在当我用 tr td .list 删除添加的文本时,它是
感谢 SO 的出色贡献者!当您开始了解 jQuery 时,它会变得更酷。 :) 所以我有一个 LI,单击时会显示/隐藏子 UL。我想做的是能够单击 LI 内的链接,打开一个空白窗口,但也不会关闭子 U
我有这份文档,它使我能够获得一份带有点击进度的多项选择选择调查问卷。 如何用图像代替此处的文字? (并且仍然有这样的机制,一旦单击[图像],就会提出下一个问题) 我已经尝试使用 UL/H1 设置背景图
我想在 JQGrid 的刷新按钮单击上编写代码。有什么事件吗? 最佳答案 如果您需要在开始刷新之前执行一些操作,您应该使用 beforeRefresh打回来: $("#grid_id").jqGrid
问题是将对象或多个参数从模板传递到组件,并使用它们将数据添加到 API。 任务.service.ts addTasks(task: Task): Observable{ let headers =
我有一个像这样的primefaces选项卡 View : This tab has static content. this t
我在 jquery 中有一个有效的 a.click() 函数...但是如果我单击一个 anchor ,我会打开一个新窗口...但是我怎样才能阻止浏览器本身打开一个新窗口? 示例: $('a')
有没有简单的方法来创建代码:如果 URL 更改或单击链接显示 div(例如加载 gif 3 秒),则显示页面?有点像空白的白色页面,加载 gif 旋转 3 秒然后显示页面? 谢谢! 最佳答案 给定 G
我需要知道此时按钮的状态是否被点击? 谢谢 最佳答案 if (myButton.state & UIControlStateHighlighted) { // Do your stuff the
我正在 NSImageView 上绘制一条 NSBezierPath 线。我正在创建 NSBezierPath 对象,设置 moveToPoint,设置 lineToPoint,设置 setLineW
我的 Selenium 代码存在问题,无法正确执行按键 + 单击操作。 测试应打开 jqueryui.com 链接并选择页面上的前 2 个 li 元素。 我正在使用 Selenium 2.23 和 F
单击时我将更改字符串一部分的样式。例如“TEXT”,然后单击“T”,之后它会将样式从黑色更改为红色,仅 T在我的代码中,当我单击文本时,我拆分文本并保留在“split”数组中,它将调用handleCl
我在网站上有一个 anchor 。当有人点击它时,我在 jquery 中执行一些操作并更改名称,但是当再次单击它时,事件被触发,尽管我已经更改了它的名称。代码在这里: $(".like_cont a[
我有一个下载链接Download我希望每次当有人点击“下载”时,我都可以将其插入数据库total_downloads+1。为了插入数据库,我通常使用 然后 if (isset($_POST['d
我是一名优秀的程序员,十分优秀!