Java 界面类问题,求解决

为什么文本框里乱七八糟的
代码:
package 评价;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
class J_ActionListener1 extends JFrame implements ActionListener
//添加信息
{ String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";

String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=pingjia";

String userName="sa";

String userPwd="123456";
final DataBase a=new DataBase();
public void tianjia1()
{

JFrame tianjia1=new JFrame();
tianjia1.setTitle("开始评价,请输入数据:") ; //创建框架的标题
tianjia1.setSize(600,500);
tianjia1.setLocation(600, 500) ;

tianjia1.setResizable(false);

tianjia1.setVisible(true);

JPanel c=new JPanel(){
public void paintComponent(Graphics g) {
ImageIcon icon =
new ImageIcon("E:\2.jpg");
g.drawImage(icon.getImage(), 0, 0, this.getSize().width,this.getSize().height,this);
}
};
c.setLayout(null);
tianjia1.add(c);

JLabel jlb1 = new JLabel("编号:") ;

jlb1.setBounds(20,20,70,40) ;

c.add(jlb1) ;

JLabel jlb2 = new JLabel("学号:") ;

jlb2.setBounds(310,20,70,40) ;
c.add(jlb2) ;
JLabel jlb3 = new JLabel("教师号:") ;
jlb3.setBounds(20,70,70,40) ;
c.add(jlb3) ;
JLabel jlb4 = new JLabel("教学氛围:") ;
jlb4.setBounds(310,70,70,40) ;
c.add(jlb4) ;
JLabel jlb5 = new JLabel("教学能力:") ;
jlb5.setBounds(20,120,70,40) ;
c.add(jlb5) ;
JLabel jlb6 = new JLabel("教学内容") ;
jlb6.setBounds(310,120,70,40) ;
c.add(jlb6) ;
JLabel jlb7 = new JLabel("综合") ;
jlb7.setBounds(20,170,70,40) ;
c.add(jlb7) ;
final JTextField jtf1 = new JTextField();

final JTextField jtf2 = new JTextField();
final JTextField jtf3 = new JTextField();
final JTextField jtf4 = new JTextField();
final JTextField jtf5 = new JTextField();
final JTextField jtf6 = new JTextField();
final JTextField jtf7 = new JTextField();
JButton btn1 = null ;
JButton btn2 = null ;
jtf1.setBounds(110,20,100,40) ;
jtf1.setOpaque(false);
c.add(jtf1) ;
jtf2.setBounds(400,20,100,40) ;
jtf2.setOpaque(false);
c.add(jtf2) ;
jtf3.setBounds(110,70,100,40) ;
jtf3.setOpaque(false);
c.add(jtf3) ;
jtf4.setBounds(400,70,100,40) ;
jtf4.setOpaque(false);
c.add(jtf4) ;
jtf5.setBounds(110,120,100,40) ;
jtf5.setOpaque(false);
c.add(jtf5) ;
jtf6.setBounds(400,120,100,40) ;
jtf6.setOpaque(false);
c.add(jtf6) ;
jtf7.setBounds(110,170,100,40) ;
jtf7.setOpaque(false);
c.add(jtf7) ;
btn1 = new JButton("保存") ;

btn1.setBounds(310,170,60,40) ;

c.add(btn1) ;

btn1.addActionListener(new ActionListener()

{
public void actionPerformed( ActionEvent e)

{
JButton tj=(JButton)e.getSource();
String ID=jtf1.getText();

String js=jtf2.getText();
String xs=jtf3.getText();
String fenwei=jtf4.getText();
String nengli=jtf5.getText();
String neirong=jtf6.getText();
String zong=jtf7.getText();
try {
a.Add(ID,js, xs, fenwei, nengli, neirong, zong);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

tianjia1.setVisible(false);
}
});

          btn2 = new JButton("取消") ;                    
          btn2.setBounds(400,170,60,40) ;             
          c.add(btn2) ;                           
          btn2.addActionListener(new ActionListener()                   
           { 
              public void actionPerformed( ActionEvent e)               
               {
                    tianjia1.setVisible(false);
               }
           });                          
     }


      public void actionPerformed(ActionEvent e)
      {   
          JButton b1=(JButton)e.getSource();                
          Object aa= JOptionPane.showInputDialog(null, "请选择评价对象","选择", 
                  JOptionPane.QUESTION_MESSAGE,null,new String []{"教师",
                         },"学生");

          if(aa=="教师")
          {
              this.tianjia1(); 
          }

      }

}图片说明

2个回答

public void paintComponent(Graphics g)
你自己去画,又没画对,所以就乱了。为什么要自己画呢?你想画什么?

weixin_38502364
weixin_38502364 谢谢,已解决
一年多之前 回复

public void paintComponent(Graphics g)存在问题

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!