当前位置: 技术问答>java相关
在线等待,文件对话框问题!!!!!解决一定送分
来源: 互联网 发布时间:2015-09-07
本文导语: 源代码如下: import java.awt.*; import java.awt.event.*; public class FileDialogExample implements ActionListener{ Frame f; Button b; TextArea ta; FileDialog fd; static public void main(String args[]){ FileDialogExample fde=new FileDialogExample(); fde.g...
源代码如下:
import java.awt.*;
import java.awt.event.*;
public class FileDialogExample implements ActionListener{
Frame f;
Button b;
TextArea ta;
FileDialog fd;
static public void main(String args[]){
FileDialogExample fde=new FileDialogExample();
fde.go();
}
public void go(){
f=new Frame("FileDialog Example");
b=new Button("show filedialog");
b.addActionListener(this);
f.add("South",b);
ta=new TextArea();
fd=new FileDialog(f,"FileDialog");
f.setSize(350,150);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
fd.setVisible(true);
ta.append("Directory: "+fd.getDirectory());
ta.append("nFilename: "+fd.getFile());
}
}
编译是成功的,对话框也可以打开,但文本区却显示不出来内容,我已经加了
ta.append("Directory: "+fd.getDirectory());
ta.append("nFilename: "+fd.getFile());
为什么没东西显示呢?
import java.awt.*;
import java.awt.event.*;
public class FileDialogExample implements ActionListener{
Frame f;
Button b;
TextArea ta;
FileDialog fd;
static public void main(String args[]){
FileDialogExample fde=new FileDialogExample();
fde.go();
}
public void go(){
f=new Frame("FileDialog Example");
b=new Button("show filedialog");
b.addActionListener(this);
f.add("South",b);
ta=new TextArea();
fd=new FileDialog(f,"FileDialog");
f.setSize(350,150);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
fd.setVisible(true);
ta.append("Directory: "+fd.getDirectory());
ta.append("nFilename: "+fd.getFile());
}
}
编译是成功的,对话框也可以打开,但文本区却显示不出来内容,我已经加了
ta.append("Directory: "+fd.getDirectory());
ta.append("nFilename: "+fd.getFile());
为什么没东西显示呢?
|
你没把ta加到Frame中去。应该加上这句:f.add(ta);
import java.awt.*;
import java.awt.event.*;
public class FileDialogExample implements ActionListener{
Frame f;
Button b;
TextArea ta;
FileDialog fd;
static public void main(String args[]){
FileDialogExample fde=new FileDialogExample();
fde.go();
}
public void go(){
f=new Frame("FileDialog Example");
b=new Button("show filedialog");
b.addActionListener(this);
f.add("South",b);
ta=new TextArea();
f.add(ta); //
fd=new FileDialog(f,"FileDialog");
f.setSize(350,150);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
fd.setVisible(true);
ta.append("Directory: "+fd.getDirectory());
ta.append("nFilename: "+fd.getFile());
}
}
import java.awt.*;
import java.awt.event.*;
public class FileDialogExample implements ActionListener{
Frame f;
Button b;
TextArea ta;
FileDialog fd;
static public void main(String args[]){
FileDialogExample fde=new FileDialogExample();
fde.go();
}
public void go(){
f=new Frame("FileDialog Example");
b=new Button("show filedialog");
b.addActionListener(this);
f.add("South",b);
ta=new TextArea();
f.add(ta); //
fd=new FileDialog(f,"FileDialog");
f.setSize(350,150);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
fd.setVisible(true);
ta.append("Directory: "+fd.getDirectory());
ta.append("nFilename: "+fd.getFile());
}
}
|
老弟你太粗心了
import java.awt.*;
import java.awt.event.*;
public class FileDialogExample implements ActionListener{
Frame f;
Button b;
TextArea ta;
FileDialog fd;
static public void main(String args[]){
FileDialogExample fde=new FileDialogExample();
fde.go();
}
public void go(){
f=new Frame("FileDialog Example");
b=new Button("show filedialog");
b.addActionListener(this);
f.add("South",b);
ta=new TextArea();
f.add("Center",ta);//note this
fd=new FileDialog(f,"FileDialog");
f.setSize(350,150);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
fd.setVisible(true);
ta.append("Directory: "+fd.getDirectory());
ta.append("nFilename: "+fd.getFile());
}
}
import java.awt.*;
import java.awt.event.*;
public class FileDialogExample implements ActionListener{
Frame f;
Button b;
TextArea ta;
FileDialog fd;
static public void main(String args[]){
FileDialogExample fde=new FileDialogExample();
fde.go();
}
public void go(){
f=new Frame("FileDialog Example");
b=new Button("show filedialog");
b.addActionListener(this);
f.add("South",b);
ta=new TextArea();
f.add("Center",ta);//note this
fd=new FileDialog(f,"FileDialog");
f.setSize(350,150);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e){
fd.setVisible(true);
ta.append("Directory: "+fd.getDirectory());
ta.append("nFilename: "+fd.getFile());
}
}