import java.awt.BorderLayout;
import java.awt.Graphics;
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.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class StafffingWindow extends JFrame{
private static JTextArea jtaDescription = new JTextArea();
OperatingToSQL op = new OperatingToSQL();
private static Graphics g;
public StafffingWindow() {
add(new paint());
}
public static void main(String[] args) {
JFrame frame = new StafffingWindow();
frame.pack();
frame.setTitle("操作初始界面Vol 0.1");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
class paint extends JPanel{
JButton select = new JButton("查询数据");
JButton insert = new JButton("插入数据");
JButton update = new JButton("更改数据");
JButton delete = new JButton("删除数据");
public paint() {
select.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame win = new JFrame();
//对jtaDescription进行设置
jtaDescription.setLineWrap(true);
jtaDescription.setWrapStyleWord(true);
jtaDescription.setEditable(false);
jtaDescription.setText(op.selectTable());
win.setSize(200, 200);
win.setTitle("Infomation");
win.setVisible(true);
win.setLayout(new BorderLayout());
//将文本域放入win框架中
win.add(jtaDescription, BorderLayout.CENTER);
// win.add(setLabel(), BorderLayout.NORTH);
}
});
insert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
op.insert();
}
});
update.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
op.Update();
}
});
delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
op.Delete();
}
});
setLayout(new GridLayout(1,4));
add(select);
add(insert);
add(update);
add(delete);
}
}
/** 有问题 */
protected static JPanel setLabel() {
JPanel jlbl = new JPanel();
jlbl.paintComponents(g);
g.drawString("姓名", 0, 0);//这里报错
g.drawString("性别", 200 / 3, 0);
g.drawString("身份证号码", 200 / 3 * 2, 0);
return jlbl;
}
}
------解决方案--------------------