public class Java_1 {
public static void main(String args[]) {
int x,n;
//*********Found********
n = 0;
for( x = 100 ; x <= 200 ; x++)
if ( x % 9 == 0 ) {
//*********Found********
System.out.print(" " + x);
n++;
//*********Found********
if ( n % 5 ==0) System.out.println( );
}
}
}
import java.io.*;
import java.util.Vector;
public class Java_2{
public static void main(String s[]){
Vector v=new Vector();
try{
//*********Found**********
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //键盘输入
String str = "";
System.out.println("请输入用户和密码信息,中间用空格隔开,输入quit退出:");
while (!(str.equals("quit")||str.equals("QUIT"))){
str = in.readLine();
//*********Found**********
if(isValid(str)) //验证输入是否有空格
v.add(str);
else{
if(!(str.equals("quit")||str.equals("QUIT")))
System.out.println("The string is NOT valid!");
}
}
System.out.println("请输入保存到的文件名:");
//*********Found**********
str=in.readLine();
String curDir = System.getProperty("user.dir");
File savedfile=new File(curDir+"\\"+str);
//*********Found**********
BufferedWriter out = new BufferedWriter(new FileWriter(___________________));
for(int i=0; i<v.size(); i++){
String tmp=(String)v.elementAt(i);
out.write(tmp);
//*********Found**********
out.write("\n"); //换行
}
out.close();
}
//*********Found**********
catch(Exception e){
System.out.print("ERROR:"+e.getMessage());
}
}
/**
* 判定输入的字符串是否符合规范
* @param s 输入的待校验的字符串
* @return 校验的结果,正确则返回为真
*/
public static boolean isValid(String s){
if(s.indexOf(" ")>0) return true;
else return false;
}
}
//*********Found**********
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
//*********Found**********
public class Java_3 extends MouseAdapter implements ActionListener
{
//*********Found**********
private JPopupMenu pop;
private JMenu subPop;
private JMenuItem color;
private JMenuItem exit;
private JMenuItem red;
private JMenuItem blue;
private JTextArea textArea;
private JFrame frame;
public void initGUI()
{
pop=new JPopupMenu();
subPop=new JMenu("color");
red=new JMenuItem("red");
red.addActionListener(this);
blue=new JMenuItem("blue");
blue.addActionListener(this);
subPop.add(red);
subPop.add(blue);
exit=new JMenuItem("exit");
exit.addActionListener(this);
pop.add(subPop);
pop.add(exit);
//*********Found**********
frame=new JFrame("popup frame");
textArea=new JTextArea("",10,10);
textArea.addMouseListener(this);
frame.getContentPane().add(textArea);
frame.setSize(300,300);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{
//*********Found**********
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource()==red)
{
textArea.setForeground(Color.red);
textArea.setText("red menu is selected");
}
else if(event.getSource()==blue)
{
textArea.setForeground(Color.blue);
textArea.setText("blue menu is selected");
}
else if(event.getSource()==exit)
{
frame.setVisible(false);
System.exit(0);
}
}
public void mousePressed(MouseEvent e)
{
if(e.getModifiers()==e.BUTTON3_MASK)
{
pop.show(e.getComponent(),e.getX(),e.getY());
}
}
public static void main(String args[])
{
Java_3 example=new Java_3();
example.initGUI();
}
}