class Kadai5a extends JPanel{ Person hito; JTextField hField, wField; JLabel hyoujun, hantei, himando, message; JPanel dataPanel; OutListener listener; Kadai5a(){ message = new JLabel(" "); dataPanel = new JPanel(); setLayout(new BorderLayout()); add(message, BorderLayout.WEST); add(dataPanel,BorderLayout.SOUTH);
hField = new JTextField(10); wField = new JTextField(10); hyoujun = new JLabel(); hantei = new JLabel(); himando = new JLabel(); listener = new OutListener(this); hField.addActionListener(listener); wField.addActionListener(listener); dataPanel.setBackground(Color.white); dataPanel.setLayout(new GridLayout(5,2)); dataPanel.add(new JLabel("身長(cm)")); dataPanel.add(hField); dataPanel.add(new JLabel("体重(Kg)")); dataPanel.add(wField); dataPanel.add(new JLabel("標準体重(Kg)")); dataPanel.add(hyoujun); dataPanel.add(new JLabel("BMI(理想値:22)")); dataPanel.add(hantei); dataPanel.add(new JLabel("肥満度(%)")); dataPanel.add(himando);
hito = new Person(); } public static void main(String args[]) { JFrame f = new JFrame("Himando"); Kadai5a h = new Kadai5a(); Container c = f.getContentPane(); c.add(h, BorderLayout.CENTER); f.pack(); f.setVisible(true); } }