1编写命令行界面的应用程序,实现以下功能:使用java.io.File类及其类中的相关方法,在当前目录下创建子文件夹:java\myfile,并在myfile文件夹下创建一个文本文件read.txt;使用java.io.FileInputStream类及类中的方法读取源程序本身,通过java.io.FileOutputStream类的write方法将所读取的内容写入该文本文件中。2编写继承自窗口类JFrame的窗口界面应用程序,并在程序中实现以下功能:窗口的北边放置一个滑动杆javax.swing.JSlider对象,设置滑动杆的大小从0到100,初始位置在25,并设置滑动杆的主刻度为20,最小刻度为5;窗口的中间放置一个文本区对象,其中包含两行字符串“欢迎你”和“来到JAVA世界”,设置文本区字体为“隶书”、字体风格为Font.PLAIN,字体大小的初值为25。程序中处理滑动杆的改变事件(javax.swing.event.ChangeEvent):移动滑动杆的滑块,把文本区中的字体大小修改为滑块所代表的大小。3编写命令行界面的应用程序,实现以下功能:程序中定义有5个元素的字符串数组,使用javax.swing.JOptionPane类中的showInputDialog方法创建文本输入对话框,给字符串数组的5个元素赋值,并使用java.util.Arrays的sort方法对字符串数组按升序排序后在命令行输出,要求每行输出一个字符串。
哪位大师能帮我解决这三道问题,多谢!

解决方案 »

  1.   

    哎,都很简单。
    建议楼主参考api。
      

  2.   

    还是自己做吧,这样简单的都不自己尝试,就不要学Java了,什么都不用学算啦
      

  3.   

    帮你写一个,记得给分啊!!import java.io.*;public class IOTest {
    public static void main(String[] args){

    File dir = new File("java/myfile");
    if(!dir.exists()){
    dir.mkdirs();


    File f = new File("java/myfile/read.txt");
    if(!f.exists()){
    try{

    f.createNewFile();
    } catch (IOException e){
    System.out.println("Create File Error!");
    e.printStackTrace();
    System.exit(-1);
    }
    }

    int r;
    FileInputStream fis = null;
    FileOutputStream fos = null;
    try{
    fis = new FileInputStream("IOTest.java");
    fos = new FileOutputStream(f);

    do {
    r = fis.read();
    fos.write(r);
    }while(r!=-1);

    System.out.println("Successful!");

    } catch (FileNotFoundException e){
    System.out.println("File Not Found!");
    e.printStackTrace();
    } catch (IOException e){
    System.out.println("Read/Write File Error!");
    e.printStackTrace();
    } finally {
    if(fis!=null){
    try{

    fis.close();
    }catch(IOException e){
    e.printStackTrace();
    }
    }
    if(fos!=null){
    try{

    fos.close();
    }catch(IOException e){
    e.printStackTrace();
    }
    }

    } }
    }
      

  4.   

    File f1=new File("java");
    f1.mkdir();
    File f2=new File("java\\myfile");
    f2.mkdir();
    File f3=new File("java\\myfile\\read.txt");
    f3.createNewFile();
                      FileOutputStream fos=new FileOutputStream(f3);
    fos.write("www.csdn.net".getBytes());
    FileInputStream fis=new FileInputStream(f3);
    byte[] b=new byte[100];
    int len=fis.read(b);
    System.out.print(new String(b,0,len));
    后面的不会,awt基本没看过
      

  5.   

    就是啊,看以下JavaDoc api就会了
      

  6.   

    import java.io.*;public class IoOutFile {
    public static void main(String[] s) throws IOException{
    File fileout= new File("./java\\myfile");
    fileout.mkdirs();

    File file1=new File(fileout,"read.txt");
    file1.createNewFile();

    int i;
    FileInputStream fis=null;
    FileOutputStream fos=null;

    try{
    fis=new FileInputStream("IoOutFile.java");
    fos=new FileOutputStream(file1);

    while((i=fis.read())!=-1){
    fos.write(i);
    }
    }
    catch(Exception x){
    x.printStackTrace();
    }
    finally{
    fis.close();
    fos.close();
        }
    }
    }自己写异常吧
      

  7.   

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;public class JSliderTest extends JFrame{
    JSlider slider;
    JTextArea textArea;
    int fontSize=25;

    public JSliderTest(String s){
    super(s);
    Container contentPane=getContentPane();
    contentPane.setLayout(new BorderLayout());

    slider=new JSlider(JSlider.HORIZONTAL,0,100,25);
        slider.setPaintTicks(true);
    slider.setMajorTickSpacing(20);
    slider.setMinorTickSpacing(5);
    slider.setPaintLabels(true);
    SliderHandler handler=new SliderHandler();
    slider.addChangeListener(handler);
    contentPane.add(slider,BorderLayout.NORTH);

    textArea=new JTextArea("java/n 滚",5,20);
    textArea.setFont(new Font("隶书",Font.PLAIN,fontSize));
    textArea.setForeground(Color.red);
    contentPane.add(textArea,BorderLayout.CENTER);

    setSize(400,200);
    setVisible(true);

    } public static void main(String[] s){
    JSliderTest jSliderTest=new JSliderTest("嗷嗷");
    }
    public class SliderHandler implements ChangeListener{
    public void stateChanged(ChangeEvent e){
    fontSize=slider.getValue();
    textArea.setFont(new Font("隶书",Font.PLAIN,fontSize));
    }
    }
    }