Testmsg. Java

Source: Internet
Author: User

Import java. AWT. borderlayout;
Import javax. Swing. jpanel;
Import javax. Swing. jframe;
Import java. AWT. dimension;
Import javax. Swing. jtextfield;
Import java. AWT. rectangle;
Import java. Io. bufferedreader;
Import java. Io. file;
Import java. Io. filereader;
Import java. Io. filewriter;
Import java. Io. ioexception;
Import java. Io. inputstreamreader;
Import java. Io. printwriter;

Import javax. Swing. jlabel;
Import javax. Swing. jbutton;
Import javax. Swing. joptionpane;
Import javax. Swing. jtextarea;
Import javax. Swing. jscrollpane;
Import java. Io .*;
Import java. AWT .*;

Public class testmsg extends jframe {

Private Static final long serialversionuid = 1l;

Private jpanel jcontentpane = NULL;

Private jtextfield = NULL;

Private jlabel = NULL;

Private jbutton jbutton1 = NULL;

Private jscrollpane = NULL;

Private jtextarea = NULL;

Private jbutton jbutton2 = NULL;

/**
* This is the default constructor
*/
Public testmsg (){
Super ();
Initialize ();
}

/**
* This method initializes this
*
* @ Return void
*/
Private void initialize (){
This. setsize (604,324 );
This. setcontentpane (getjcontentpane ());
This. settitle ("jframe ");
}

/**
* This method initializes jcontentpane
*
* @ Return javax. Swing. jpanel
*/
Private jpanel getjcontentpane (){
If (jcontentpane = NULL ){
Jlabel = new jlabel ();
Jlabel. setbounds (New rectangle (9, 19, 42, 51 ));
Jlabel. settext ("path ");
Jcontentpane = new jpanel ();
Jcontentpane. setlayout (null );
Jcontentpane. Add (getjtextfield (), null );
Jcontentpane. Add (jlabel, null );
Jcontentpane. Add (getjbutton1 (), null );
Jcontentpane. Add (getjscrollpane (), null );
Jcontentpane. Add (getjbutton2 (), null );
}
Return jcontentpane;
}

/**
* This method initializes jtextfield
*
* @ Return javax. Swing. jtextfield
*/
Private jtextfield getjtextfield (){
If (jtextfield = NULL ){
Jtextfield = new jtextfield ();
Jtextfield. setbounds (New rectangle (63, 25,330, 45 ));
}
Return jtextfield;
}

/**
* This method initializes jbutton1
*
* @ Return javax. Swing. jbutton
*/
Private jbutton getjbutton1 (){
If (jbutton1 = NULL ){
Jbutton1 = new jbutton ();
Jbutton1.setbounds (New rectangle (473, 20,114, 48 ));
Jbutton1.settext ("read ");
Jbutton1.addactionlistener (New java. AWT. event. actionlistener (){
Public void actionreceivmed (Java. AWT. event. actionevent e ){

String name = jtextfield. gettext ();

File Ss = new file (name );
Try {
Filereader A = new filereader (SS );
Bufferedreader BR = new bufferedreader ();

String S = Br. Readline ();
String T = s;

While (s! = NULL ){
S = Br. Readline ();
T = T + "/N" + S;

}
T = T. substring (0, T. Length ()-4 );
Jtextarea. settext (t );
BR. Close ();

}

Catch (ioexception E1 ){

Joptionpane. showmessagedialog (null, "file path error, please enter again ");

}
}
});

}
Return jbutton1;
}

/**
* This method initializes jscrollpane
*
* @ Return javax. Swing. jscrollpane
*/
Private jscrollpane getjscrollpane (){
If (jscrollpane = NULL ){
Jscrollpane = new jscrollpane ();
Jscrollpane. setbounds (New rectangles (10,103,444,174 ));
Jscrollpane. setviewportview (getjtextarea ());
}
Return jscrollpane;
}

/**
* This method initializes jtextarea
*
* @ Return javax. Swing. jtextarea
*/
Private jtextarea getjtextarea (){
If (jtextarea = NULL ){
Jtextarea = new jtextarea ();
Jtextarea. settext ("");
}
Return jtextarea;
}

/**
* This method initializes jbutton2
*
* @ Return javax. Swing. jbutton
*/
Private jbutton getjbutton2 (){
If (jbutton2 = NULL ){
Jbutton2 = new jbutton ();
Jbutton2.setbounds (New rectangle (480,215,110, 55 ));
Jbutton2.settext ("save ");
Jbutton2.addactionlistener (New java. AWT. event. actionlistener (){
Public void actionreceivmed (Java. AWT. event. actionevent e ){
String name = jtextfield. gettext ();
String S = NULL;
S = jtextarea. gettext (); // All values are assigned to S. Therefore, you do not need to judge that while the output is directly output.
File file = new file (name );
Try {

Printwriter BR = new printwriter (New filewriter (File ));
String Nam = jtextfield. gettext ();

BR. println (s );
// S = jtextarea. gettext ();


 
 

BR. Close ();

} Catch (ioexception E2 ){

Joptionpane. showmessagedialog (null, "the file path is incorrect. Check the path ");
}

}
});
}
Return jbutton2;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.