我写了一个程序,但是发现当关闭了程序运行窗口以后命令行依然没有停止运行,必须要 ctrl+c 才能结束。请问怎么可以在关闭窗口的同时也结束命令行?需要添加怎样一段程序,添加在哪呢?
解决方案 »
- 求高手帮忙看下 我要修改密码哪错了吗 为什么改不了 我是新手 求教
- 关于File的isFile()和isDirectory()方法的疑问
- java机制修改.bat内容
- 请大家帮帮我!
- JDK 1.5下提示 “super must be in first statement in cons tructor"
- 正则表达式怎么匹配这样的[.*]{0, 1}
- 两个简单的问题
- 关于空指针异常··求解决·在线等!
- 炒冷饭喽~~~~~~~ 还请各位大虾帮忙 :)
- 请教高手:JAVA安全方面的问题
- 【急!!! 大侠们帮帮忙】用jdbc 连接Oracle为什么总是报”监听打开“
- java 数据类型问题 求高人 帮忙
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.io.*;
public class CeShiFile extends JFrame implements ActionListener
{
JLabel jlbName = new JLabel("文件名");
JTextField tfName = new JTextField(20);
JButton btnOpen = new JButton("打开文件");
JButton btnSave = new JButton("存储文件");
JTextArea taText = new JTextArea(5,20);
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel(new BorderLayout());
JPanel p5 = new JPanel(new BorderLayout());
public CeShiFile()
{
p1.add(jlbName);
p2.add(tfName);
p3.add(btnOpen);
p3.add(btnSave);
JScrollPane s = new JScrollPane(taText);
p4.add(p1,BorderLayout.NORTH);
p4.add(p2,BorderLayout.CENTER);
p4.add(p3,BorderLayout.SOUTH);
p5.add(p4,BorderLayout.NORTH);
p5.add(s,BorderLayout.CENTER);
getContentPane().add(p5,BorderLayout.CENTER);
btnOpen.addActionListener(this);
btnSave.addActionListener(this);
}
public void actionPerformed(ActionEvent a)
{
try
{
String arg = a.getActionCommand();
String str = tfName.getText();
byte buf[] = new byte[2056];
int bytes;
if(arg == "打开文件")
{
FileInputStream fileIn = new FileInputStream(str);
bytes = fileIn.read(buf,0,2056);
String strin = new String(buf,0,bytes);
taText.setText(strin);
}
else if(arg == "存储文件")
{
String str1 = taText.getText();
buf = str1.getBytes();
FileOutputStream fileOut = new FileOutputStream(str);
fileOut.write(buf,0,buf.length);
fileOut.flush();
fileOut.close();
}
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
public static void main(String args[])
{
CeShiFile CS = new CeShiFile();
CS.setSize(300,300);
CS.show();
}
}
CeShiFile CS = new CeShiFile();
CS.setSize(300,300);
CS.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 加上这句就行
CS.show();
}
jar的格式是不是不能直接在电脑上运行?