publicclassShoppetextendsJFrame{publicShoppet(){JFrameframe=newJFrame("进击的宠物店");String[]titles={"宠物名字","宠物颜色","宠物性别","宠物年龄","宠物价格","剩余数量"};O...
public class Shoppet extends JFrame {
public Shoppet(){
JFrame frame = new JFrame("进击的宠物店") ;
String[] titles = {"宠物名字","宠物颜色","宠物性别","宠物年龄","宠物价格","剩余数量"} ;
Object [][] userInfo = {
{"白猫","白色","雄性","1岁","10元","5只"} ,
{"白猫","白色","雌性","1岁","10元","5只"} ,
{"黑猫","黑色","雄性","1岁","10元","5只"} ,
} ;
JTable table = new JTable(userInfo,titles) ;
JScrollPane scr = new JScrollPane(table) ;
frame.add(scr) ;
frame.setSize(600,303) ;
frame.setLocation(500,200) ;
frame.setVisible(true) ;
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent arg0){
System.exit(1);
}
});
JButton but=new JButton("购买");
frame.setLayout(null);
Font fnt=new Font("Serief",Font.BOLD,28);
JButton purchase = new JButton("购买");
JButton purchase1 = new JButton("购买");
JButton purchase2 = new JButton("购买");
purchase.setBounds(581,22,80,17);
purchase1.setBounds(581,38,80,17);
purchase2.setBounds(581,54,80,17);
frame.add(purchase);
frame.add(purchase1);
frame.add(purchase2);
frame.setVisible(true);
String picPath="f:"+File.separator+"mldn.gif";
Icon icon=new ImageIcon(picPath);
JLabel lab =null;
lab =new JLabel (icon,JLabel.CENTER);
lab.setBackground(Color.YELLOW);
lab.setForeground(Color.RED);
frame.add(lab);
frame.setSize(300,160);
frame.setBackground(Color.WHITE);
frame.setLocation(500,300);
frame.setVisible(true);
}
}
展开