Java界面设计样式
Java代码:
-------------------------------------------------------------------------------------------------------------------
package JavaSample; import java.awt.Container; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JPopupMenu; import javax.swing.JSplitPane; import javax.swing.JTextField; public class JavaSampleMain extends javax.swing.JFrame { private static final long serialVersionUID = 6818610491629713210L; private JSplitPane jSplitPaneHorizontal; // 水平分窗口 private JSplitPane jSplitPaneVertical; // 垂直分窗口 private JPanel jPanelRight; // 右窗口 private JButton jButton1; // 按钮1 private JButton jButton2; // 按钮2 //功能描述: 构造函数 public JavaSampleMain() { JPopupMenu.setDefaultLightWeightPopupEnabled(false);//防止被播放窗口(AWT组件)覆盖 initInterface(); } //功能描述: 初始化接口 private void initInterface() { jSplitPaneHorizontal = new javax.swing.JSplitPane(); jSplitPaneVertical = new javax.swing.JSplitPane(); jPanelRight = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); setTitle("JavaSampleMain"); setFont(new java.awt.Font("宋体", 0, 10)); } //功能描述: 窗口置中 public static void centerWindow(Container window) { Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int w = window.getSize().width; int h = window.getSize().height; int x = (dim.width - w) / 2; int y = (dim.height - h) / 2; window.setLocation(x, y); } //功能描述: 主界面入口函数 public static void main(String[] args) { try { javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception e) { e.printStackTrace(); } java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JavaSampleMain mainEntry = new JavaSampleMain(); centerWindow(mainEntry); mainEntry.setVisible(true); } }); } }
-------------------------------------------------------------------------------------------------------------------
posted on 2012-10-24 10:46 xuejianhui 阅读(854) 评论(0) 编辑 收藏 举报