rt
解决方案 »
- JDBC问题,为什么我的TYPE_SCROLL_SENSITIVE和TYPE_SCROLL_INSENSITIVE不起效果?
- JFrame添加组件
- 求助用IP地址访问服务器问题
- 一个非常简单的问题,情大家帮助!
- 急问:怎么消除在applet的paint()中画图时抖动的问题!!
- 求助,一个classpath的问题
- 如何看《Thinking in java》这本书?
- java socket进行交互数据的一点疑问
- import采用指定到单个文件好,还是用*好?
- 我在红帽Linux下用rpm -i j2sdk-1_3_0-linux.rpm安装了jdk1.3,java装载到了/usr/java下,接下来我该how to do?
- 在类里面 如何将回车去掉
- 求助:JAVA窗口切换面板,实现不同的界面
// Note: source for ExampleFileFilter can be found in FileChooserDemo,
// under the demo/jfc directory in the JDK.
ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension("jpg");
filter.addExtension("gif");
filter.setDescription("JPG & GIF Images");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}
public void openFileMethod() {
if (!(text.getText().equals(""))) {
if (!(text.getText().equals(textBuffer.getText()))) {
int value = this.YES_NO_CANCEL_DIALOG();
if (value == JOptionPane.YES_OPTION){
this.saveMethod();
text.setText("");
} else if (value == JOptionPane.CENTER_ALIGNMENT) {
text.setText("");
} else {
}
}
}
dialog = new FileDialog(notepad, "打开", FileDialog.LOAD);
dialog.setVisible(true);
try {
FileReader fr = new FileReader(dialog.getDirectory()
+ dialog.getFile());
BufferedReader br = new BufferedReader(fr);
String str = "";
while ((str = br.readLine()) != null) {
text.append(str + '\n');
}
notepad.setFilePath(dialog.getDirectory() + dialog.getFile());
notepad
.setTitle(notepad.getFilePath() + " - "
+ notepad.getTitle());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
这是我写的一个“打开”功能的方法,但还是有很多BUG,比如说要实现文件有改变时弹出的提示框,我们点取消后却不能实现应该实现的功能,希望高手们能帮忙解决下!
// 打开文件的方法
public void openFileMethod() {
if (!(text.getText().equals(""))) {
if (!(text.getText().equals(textBuffer.getText()))) {
int value = this.YES_NO_CANCEL_DIALOG();
if (value == JOptionPane.YES_OPTION){
this.saveMethod();
text.setText("");
} else if (value == JOptionPane.CANCEL_OPTION) {
text.setText("");
} else {
}
}
}
dialog = new FileDialog(notepad, "打开", FileDialog.LOAD);
dialog.setVisible(true);
try {
FileReader fr = new FileReader(dialog.getDirectory()+ dialog.getFile());
BufferedReader br = new BufferedReader(fr);
String str = "";
while ((str = br.readLine()) != null) {
text.append(str + '\n');
}
notepad.setFilePath(dialog.getDirectory() + dialog.getFile());
notepad.setTitle(notepad.getFilePath() + " - " + notepad.getTitle());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}