import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Mainclass {public static void main(String[] args) {
Star1 s1=new Star1();
}
}
class Star1 extends JWindow implements ActionListener
{private JTextField t1;
private JTextField t2;
public Star1(){
setLocation(10,20);
setSize(500,400);
final ImageIcon c=new ImageIcon("2.jpg");
JPanel jp=new JPanel(){
   public void paintComponent(Graphics g)
   {
   g.drawImage(c.getImage(),0,0,null);
           super.paintComponent(g);
   }   
};
JLabel l1=new JLabel("Name");
t1=new JTextField(10);
t2=new JTextField(10);
JLabel l2=new JLabel("Password");
jp.add(l1);
jp.add(t1);
jp.add(l2);
jp.add(t2);
t1.setEditable(true);
t2.setEditable(true);
JButton ok=new JButton("OK");
JButton cal=new JButton("Cancle");
jp.add(ok);
jp.add(cal);
ok.addActionListener(this);
cal.addActionListener(this);
jp.setOpaque(false);
setContentPane(jp);setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("OK"))
{
String aa=t1.getText();
String bb=t2.getText();
if(aa.equals("byr")&&bb.equals("byr"))
{
this.dispose();
}
}
if(e.getActionCommand().equals("Cancle"))
{
this.dispose();
System.exit(0);
}
}
}为什么运行后 t1,t2 不能输入啊?

解决方案 »

  1.   

    哦Creates a window with no specified owner. This window will not be focusable.是不是这个原因阿?
    那怎么才能实现可以输入的图画界面阿?谢谢
      

  2.   

    class Star1 extends JFrame implements ActionListener 
      

  3.   

    使用 JFrame 会有边框啊,怎样才能只有图片界面呢
      

  4.   

    Frame 可以都隐藏了他们,方法忘记了你查看api就有了