Advertisement
badwolves1986

java layout

Sep 11th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1. /**
  2.  * @(#)bad.java
  3.  * @program application desktop
  4.  * @author : badwolves1986
  5.  * @thanks to R3c0gnized your my inspirate ,my friend,and you my love
  6.  * @version 1.00 2011/9/11
  7.  */
  8.  
  9. import java.awt.*;
  10. import java.awt.event.*;
  11. import java.applet.Applet;
  12. import javax.swing.*;
  13.  
  14. public class bad extends Applet {
  15.     JPanel panel_1;
  16.     JTextArea bd86;
  17.     JScrollPanel sp_bd86;
  18.  
  19.     public void init() {
  20.         badLayout customLayout = new badLayout();
  21.  
  22.         setFont(new Font("Helvetica", Font.PLAIN, 12));
  23.         setLayout(customLayout);
  24.  
  25.         panel_1 = new JPanel();
  26.         add(panel_1);
  27.  
  28.         bd86 = new JTextArea("0x001986");
  29.         sp_bd86 = new JScrollPanel(bd86);
  30.         add(sp_bd86);
  31.  
  32.         setSize(getPreferredSize());
  33.  
  34.     }
  35.  
  36.     public static void main(String args[]) {
  37.         wae applet = new wae();
  38.         Frame window = new Frame("wae");
  39.  
  40.         window.addWindowListener(new WindowAdapter() {
  41.             public void windowClosing(WindowEvent e) {
  42.                 System.exit(0);
  43.             }
  44.         });
  45.  
  46.         applet.init();
  47.         window.add("Center", applet);
  48.         window.pack();
  49.         window.setVisible(true);
  50.     }
  51. }
  52.  
  53. class waeLayout implements LayoutManager {
  54.  
  55.     public badLayout() {
  56.     }
  57.  
  58.     public void addLayoutComponent(String name, Component comp) {
  59.     }
  60.  
  61.     public void removeLayoutComponent(Component comp) {
  62.     }
  63.  
  64.     public Dimension preferredLayoutSize(Container parent) {
  65.         Dimension dim = new Dimension(0, 0);
  66.  
  67.         Insets insets = parent.getInsets();
  68.         dim.width = 320 + insets.left + insets.right;
  69.         dim.height = 240 + insets.top + insets.bottom;
  70.  
  71.         return dim;
  72.     }
  73.  
  74.     public Dimension minimumLayoutSize(Container parent) {
  75.         Dimension dim = new Dimension(0, 0);
  76.         return dim;
  77.     }
  78.  
  79.     public void layoutContainer(Container parent) {
  80.         Insets insets = parent.getInsets();
  81.  
  82.         Component c;
  83.         c = parent.getComponent(0);
  84.         if (c.isVisible()) {c.setBounds(insets.left+64,insets.top+40,216,160);}
  85.         c = parent.getComponent(1);
  86.         if (c.isVisible()) {c.setBounds(insets.left+80,insets.top+56,184,128);}
  87.     }
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement