import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Sb extends Frame implements ActionListener,WindowListener{
JFrame fra=new JFrame();
JButton bt1=new JButton("大写转换小写");
JLabel lb1=new JLabel("大写");
JLabel lb2=new JLabel("小写");
JTextField tf1=new JTextField("",8);
JTextField tf2=new JTextField("",8);
public Sb(){
fra.setSize(500,200);
fra.setLayout(new FlowLayout());
fra.setTitle("大小写转换");
fra.add(lb1);
fra.add(tf1);
fra.add(bt1);
fra.add(lb2);
fra.add(tf2);
    lb1.setForeground(Color.green);
    lb2.setForeground(Color.RED);
bt1.addActionListener(this);
fra.addWindowListener(this);
fra.setVisible(true);

}
public void actionPerformed(ActionEvent e){
JButton bt=(JButton)e.getSource();
if(bt==bt1)
zhuanhuan();
}
public  void zhuanhuan(){
String st1=tf1.getText();
String st2=st1.toLowerCase();
tf2.setText(st2);
}
public static void main(){
Sb s=new Sb();
} public void windowOpened(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(1);
}
public void windowClosed(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
}

解决方案 »

  1.   

    public static void main(){ 
    Sb s=new Sb(); 
      

  2.   

    用JFrame(this,true)吧有无人知道IT界邪童丘的事迹?
    http://www.geocities.com/it_super_manager
      

  3.   

    什么叫出现两个窗口?main方法都写错了,这是Java
    public static void main(String[] args) {
    Sb s = new Sb();
    }
      

  4.   


    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class Change extends JFrame implements ActionListener{
    private JTextField textField1 = new JTextField();
    private JTextField textField2 = new JTextField();
    private JButton button    = new JButton("转换");
    public Change(){
    this.setLayout(new BorderLayout());
    textField1.setColumns(10);
    textField2.setColumns(20);
    textField2.setEditable(false);
    JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayout(1,2));
    panel1.add(textField1);
    panel1.add(button);
    button.addActionListener(this);
    this.add(panel1,BorderLayout.NORTH);

    JPanel panel2 = new JPanel();
    panel2.setLayout(new FlowLayout(FlowLayout.CENTER));
    panel2.add(textField2);
    this.add(panel2,BorderLayout.SOUTH);
    }
    public void actionPerformed(ActionEvent e) {
    String text = textField1.getText();
    text = text.toUpperCase();
    textField2.setText(text);

    }

    public static void main(String[] args) {
    Change change = new Change();
    change.setBounds(0, 0, 500, 500);
    change.pack();
    change.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    change.setVisible(true);
    }
     
    }