Java Reference
In-Depth Information
pack();
setVisible(true);
}
private JButton makePrettyButton(String title) {
JButton button = new JButton(title);
button.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 16));
button.setBorder(BorderFactory.createRaisedBevelBorder());
button.setBackground(Color.white);
button.setForeground(new Color(53, 124, 255));
return button;
}
private JTextField makePrettyTextField() {
JTextField field = new JTextField();
field.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 14));
field.setHorizontalAlignment(JTextField.RIGHT);
field.setBorder(BorderFactory.createLoweredBevelBorder());
return field;
}
private JLabel makePrettyLabel(String title) {
JLabel label = new JLabel(title);
label.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14));
label.setForeground(new Color(53, 124, 255));
return label;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new BMICalculator();
}
});
}
}
4.
To add a behavior to the Calculate button, change the class once again to look as follows:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
Search WWH ::




Custom Search