import java.awt.BorderLayout
import java.awt.Color
import java.awt.Dimension
import java.awt.GridLayout
import javax.swing.JFrame
import javax.swing.JPanel
import javax.swing.SwingUtilities
public class PanelRunner extends JFrame
{
private static final long serialVersionUID = 1L
private static void initPanels ( JFrame pr )
{
for ( int i = 0 i < 5 i++ )
{
JPanel panel = new JPanel ()
switch (i)
{
case 0:
panel.setBackground (Color.RED)
panel.setPreferredSize (new Dimension (200, 100))
pr.add (panel, BorderLayout.NORTH)
break
case 1:
panel.setBackground (Color.YELLOW)
panel.setPreferredSize (new Dimension (200, 300))
pr.add (panel, BorderLayout.EAST)
break
case 2:
panel.setBackground (Color.ORANGE)
panel.setPreferredSize (new Dimension (200, 100))
pr.add (panel, BorderLayout.SOUTH)
break
case 3:
panel.setBackground (Color.WHITE)
panel.setPreferredSize (new Dimension (200, 300))
pr.add (panel, BorderLayout.WEST)
break
case 4:
pr.add (panel, BorderLayout.CENTER)
panel.setPreferredSize (new Dimension (200, 100))
panel.setLayout (new GridLayout (1, 2))
for ( 源改猜int j = 0 j < 2 j++ )
{
JPanel subPanel = new JPanel ()
subPanel.setPreferredSize (new Dimension (200, 100))
Color color = j == 0 ? Color.BLUE : Color.GREEN
subPanel.setBackground (color)
panel.add (subPanel)
}
break
default:
break
}
}
}
private static void initFrame ( JFrame pr )
{
pr.setLayout (new BorderLayout ())
pr.setSize (600, 300)
pr.setLocationRelativeTo (null)
pr.setResizable (false)
pr.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE)
}
public static void main ( String[] args )
{
SwingUtilities.invokeLater (new Runnable ()
{
@Override
public void 雹型run ()
{
PanelRunner pr = 歼绝new PanelRunner ()
initFrame (pr)
initPanels (pr)
pr.setVisible (true)
}
})
}
}
CS结构系统的退出如下察氏:public void init() {\x0d\x0a this.setTitle("用户登录界面")\x0d\x0a this.add(createCenterPane())\x0d\x0a this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE)\x0d\x0a this.setSize(new Dimension(450, 335))\x0d\x0a this.setLocationRelativeTo(null)\x0d\x0a // this.setVisible(true)\x0d\x0a this.addWindowListener(new WindowAdapter() {\x0d\x0a public void windowClosing(WindowEvent e) {\x0d\x0aint choose = JOptionPane.showConfirmDialog(null, "是否要枝没慎退出登录界猛敬面?",\x0d\x0a "系统提示:", JOptionPane.YES_NO_OPTION)\x0d\x0aif (choose == JOptionPane.YES_OPTION) {\x0d\x0a System.exit(1)\x0d\x0a}\x0d\x0a }\x0d\x0a })\x0d\x0a }其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行了!欢迎分享,转载请注明来源:内存溢出
评论列表(0条)