java 第7章 图形用户界面.ppt
文本预览下载声明
* 439。57秒 * 439。57秒 * 439。57秒 * 439。57秒 * 439。57秒 * 439。57秒 * 439。57秒 * 439。57秒 * 439。57秒 * 439。57秒 * 439。57秒 * * * 439。57秒 * 439。57秒 图形用户界面 * Setting Colors You can use the following methods to set the component’s background and foreground colors: setBackground(Color c) setForeground(Color c) Example: jbt.setBackground(Color.yellow); jbt.setForeground(Color.red); 图形用户界面 * 12.7 The Font Class Font myFont = Font(name, style, size); Example: Font myFont = new Font(SansSerif , Font.BOLD, 16); Font myFont = new Font(Serif, Font.BOLD+Font.ITALIC, 12); JButton jbtOK = new JButton(OK“); jbtOK.setFont(myFont); Font Names Standard font names that are supported in all platforms are: SansSerif, Serif, Monospaced, Dialog, or DialogInput. Font Style Font.PLAIN (0), Font.BOLD (1), Font.ITALIC (2), and Font.BOLD + Font.ITALIC (3) 图形用户界面 * Finding All Available Font Names import java.awt.*; public class TestFont{ public static void main(String[]args){ GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontnames = e.getAvailableFontFamilyNames(); for (int i = 0; i fontnames.length; i++) System.out.println(fontnames[i]); }} 图形用户界面 * 12.8 Using Panels as Sub-Containers Panels act as sub-containers for grouping user interface components. It is recommended that you place the user interface components in panels and place the panels in a frame. You can also place panels in a panel. To add a component to JFrame, you actually add it to the content pane of JFrame. To add a component to a panel, you add it directly to the panel using the add method. 图形用户界面 * Creating a JPanel You can use new JPanel() to create a panel with a default FlowLayout manager or new JPanel(LayoutManager) to create a panel with the specified layout manager. Use the add(Component) method to add a component to the panel. For example, JPanel p = new JPanel(); p.add(new JButton(OK)); 图形用户界面 * Example 12.4 Testing Panels This example uses panels to organize components. The prog
显示全部