importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.awt.GridLayout;publicclassCiextendsJFrameimplementsActionListener{protectedJPanela;protectedJLabels...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.GridLayout;
public class Ci extends JFrame implements ActionListener{
protected JPanel a;
protected JLabel si;
protected JLabel qing;
protected JTextField wen;
protected JButton q;
protected String ll;
Ci(){
this.setBounds(100,100,420,320);
a=new JPanel();
si=new JLabel("i");
qing=new JLabel("请输入关键字");
wen=new JTextField(10);
q=new JButton("确定");
q.addActionListener(this);;
a.add(si);
a.add(qing);
a.add(wen);
a.add(q);
kk();
a.setLayout(new GridLayout(10,5));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(a);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==q){
if(wen.getText().equals(ll)){
this.setTitle("正确");
this.wen.setText("");
kk();
}else{
JOptionPane.showMessageDialog(this,"错误");
}
}
}
public static void main(String[]args){
new Ci();
}
private void kk(){
String aa[]={"是","否","公共的","私有的","受保护的"};
String bb[]={"yes","no","public","private","protected"};
int cc=(int)(Math.random()*aa.length);
String c=aa[cc];
si.setText(c);
this.ll=bb[cc];
JPanel panel = new JPanel(){
protected void paintComponent(Graphics g){
super.paintComponent(g);
Image image = new ImageIcon("D:/tuan/5830.jpg").getImage();
int width = Tupian.getFrames()[0].getWidth();
int heigh = Tupian.getFrames()[0].getHeight();
g.drawImage(image, 0, 0, width, heigh, null);
}
};
add(panel);
setBounds(500, 100, 480, 320);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
程序已运行就把里面的内容覆盖了,怎么让他不覆盖?
展开