更新时间: 试题数量: 购买人数: 提供作者:

有效期: 个月

章节介绍: 共有个章节

收藏
搜索
题库预览

(含图)import javax.swing.JOptionPane;

public class Java_1{

public static void main( String args[] ){

String s1, s2, s3, s4, output;

s1 = new String( "hello" );

s2 = new String( "good bye" );

s3 = new String( "Happy Birthday" );

s4 = new String( "happy birthday" );

output = "s1 = " + s1 + "\ns2 = " + s2 +

"\ns3 = " + s3 + "\ns4 = " + s4 + "\n\n";

//测试字符串相等

if ( s1.equals( "hello" ) )

/*********Fill********/

output = output + "_________________________";

else

output = output + "s1 does not equal \"hello\"\n";

//用==测试相等

if ( s1 == "hello" )

output += "s1 equals \"hello\"\n";

else

output += "s1 does not equal \"hello\"\n";

//忽略字符格式测试相等

if ( s3.equalsIgnoreCase( s4 ) )

output += "s3 equals s4\n";

else

output += "s3 does not equal s4\n";

//内容比较

output +=

"\ns1.compareTo( s2 ) is " + s1.compareTo( s2 ) +

"\ns2.compareTo( s1 ) is " + s2.compareTo( s1 ) +

"\ns1.compareTo( s1 ) is " + s1.compareTo( s1 ) +

"\ns3.compareTo( s4 ) is " + s3.compareTo( s4 ) +

"\ns4.compareTo( s3 ) is " + s4.compareTo( s3 ) +

"\n\n";

//测试包含字符格式的域匹配

if ( s3.regionMatches( 0, s4, 0, 5 ) )

output += "First 5 characters of s3 and s4 match\n";

else

output +=

"First 5 characters of s3 and s4 do not match\n";

//忽略字符格式的域匹配

if ( s3.regionMatches( true, 0, s4, 0, 5 ) )

output += "First 5 characters of s3 and s4 match";

else

output +=

"First 5 characters of s3 and s4 do not match";

/*********Fill********/

JOptionPane.______________________( null, output,

"字符串构造方法示例",

JOptionPane.INFORMATION_MESSAGE );

System.exit( 0 );

}

}

(含图)import javax.swing.*;

import java.awt.event.*;

import java.io.*;

import java.awt.*;

public class Java_3 implements ActionListener

{

private JFrame frame;

private JButton button;

private JButton saveButton;

private JTextArea textArea;

private JFileChooser dia;

private JPanel buttonPanel;

public void initGUI()

{

/*********Fill********/

frame=new JFrame("_____________________");

button=new JButton("open file");

button.setActionCommand("open");

button.addActionListener(this);

/*********Fill********/

saveButton=new JButton("______________________");

saveButton.setActionCommand("save");

saveButton.addActionListener(this);

textArea=new JTextArea("",10,10);

buttonPanel=new JPanel();

dia=new JFileChooser();

frame.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

});

buttonPanel.add(button);

buttonPanel.add(saveButton);

frame.getContentPane().add(buttonPanel,BorderLayout.NORTH);

frame.getContentPane().add(textArea,BorderLayout.CENTER);

frame.setSize(300,300);

frame.setVisible(true);

}

public void actionPerformed(ActionEvent event)

{

if(event.getActionCommand().equals("open"))

{

//打开文件?

/*********Fill********/

dia.showOpenDialog( _____________________ );

dia.setVisible(true);

File file=dia.getSelectedFile();

String fileName=file.getAbsolutePath();

textArea.append("path of selected file: "+fileName+"\r\n");

}

else if(event.getActionCommand().equals("save"))

{

//保存文件

dia.showSaveDialog(frame);

dia.setVisible(true);

File file=dia.getSelectedFile();

String fileName=file.getAbsolutePath();

textArea.append("path of saved file: "+fileName+"\r\n");

}

}

public static void main(String args[])

{

Java_3 example=new Java_3();

example.initGUI();

}

}

(含图)import java.awt.*;

import java.awt.event.* ;

 

     

/**********FILL**********/

public class Java_3 ________________ ActionListener

{

    public static void main(String args[ ])

    {

        Java_3 tb = new Java_3();

     

/**********FILL**********/

        Frame f = new Frame("________________");

        f.setSize(200,100);

        f.setLayout(new FlowLayout(FlowLayout.CENTER));

 

        Button b = new Button("Press the Button!");

     

/**********FILL**********/

        b.____________________________(tb);

 

     

/**********FILL**********/

        _________________.add(b);

        f.addWindowListener(new WindowAdapter(){

              public void windowClosing(WindowEvent e){

                 System.exit(0);

              }

        });

        f.setVisible(true) ;

    }

 

    

/**********FILL**********/

    public void _______________________(ActionEvent e)

    {

        Frame fr = new Frame("An Other");

        fr.setBackground(Color.green);

        fr.add(new Label("This frame shows when "+"pressing the button in Button Test"));

        fr.addWindowListener(new WindowAdapter(){

           public void windowClosing(WindowEvent e){

              System.exit(0);

           }

        });

        fr.pack();

        fr.setVisible(true) ;

    }

}