|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
从一个编程语言的普及程度来将,一个好的IDE是至关中要的,而现在的java的IDE虽然已经很好了,但是和.net网页编程比起来还是稍微差一些的,这是个客观事实。java要想普及的更好。DE是必须加以改进的。
importjava.awt.*;
importjava.awt.event.*;
importjava.io.*;
importjavax.swing.*;
publicclassJfilechooserextendsJFrameimplementsActionListener
{
//===================================================
JButtonbutton;
JTextAreatext;
JTextPanetextpane;
FileInputStreamreadfile;
JScrollPanescroll;
Containercon;
JFileChooserchooser=newJFileChooser();
//==========================================
publicJfilechooser()
{
super("有文件选择器的窗口");
button=newJButton("翻开文件选择器");
button.addActionListener(this);
textpane=newJTextPane();
scroll=newJScrollPane(textpane);
setSize(newDimension(400,400));
setVisible(true);
con=getContentPane();
con.add(button,BorderLayout.NORTH);
con.add(scroll,BorderLayout.CENTER);
addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
dispose();System.exit(0);}});
}
//====================================================
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==button)
{
Strings;
intstate=chooser.showOpenDialog(null);
Filefile=chooser.getSelectedFile();
if(file!=null&&state==JFileChooser.APPROVE_OPTION)
{
try{
readfile=newFileInputStream(file);
textpane.read(readfile,this);
}
catch(IOExceptione1)
{
e1.printStackTrace();
}
}
}
}
//======================================================
}
--------------------------------------------------------------------------------------------------
importjava.awt.*;
importjava.awt.event.*;
importjava.io.*;
importjavax.swing.*;
classJfilechooserextendsJFrameimplementsActionListener
{
//===================================================
JButtonbutton;
JTextAreatext;
JTextPanetextpane;
FileInputStreamreadfile;
JScrollPanescroll;
JFileChooserchooser=newJFileChooser();
JPanelcon;
//==========================================
publicJfilechooser()
{
super("有文件选择器的窗口");
button=newJButton("翻开文件选择器");
button.addActionListener(this);
textpane=newJTextPane();
scroll=newJScrollPane(textpane);
//setSize(newDimension(400,400));
//setVisible(true);
con=(JPanel)this.getContentPane();
con.add(button,BorderLayout.NORTH);
con.add(scroll,BorderLayout.CENTER);
addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
dispose();System.exit(0);}});
}
//====================================================
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==button)
{
Strings;
intstate=chooser.showOpenDialog(null);
Filefile=chooser.getSelectedFile();
if(file!=null&&state==JFileChooser.APPROVE_OPTION)
{
try{
readfile=newFileInputStream(file);
textpane.read(readfile,this);
}
catch(IOExceptione1)
{
e1.printStackTrace();
}
}
}
}
//======================================================
}
publicclassmywindow
{
publicstaticvoidmain(Stringargs[])
{
Jfilechooserwin=newJfilechooser();
win.setSize(newDimension(400,400));
win.pack();
win.validate();
win.show();
DimensionscreenSize=Toolkit.getDefaultToolkit().getScreenSize();
DimensionframeSize=win.getSize();
if(frameSize.height>screenSize.height)
{
frameSize.height=screenSize.height;
}
if(frameSize.width>screenSize.width){
frameSize.width=screenSize.width;
}
win.setLocation((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2);
}
}
=============================================================
注重:
====
====
chooser对象不克不及在机关函数中初始化!
应当在成员变量中初始化:
JFileChooserchooser=newJFileChooser();
人人能够编译测试!能够会商!由于处置办法有多种!
还是要自己一点一点写代码,然后编译,改错再编译好那。还有最重要的是.net网页编程的编译环境非常好,你甚是不需要了解太多工具,对于简单的系统,你可以之了解一些语法就哦了。 |
|