[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[jfriends] FrameÆâ ¤Î Panel¤ÎÉÁ²è¤Ë¤Ä¤¤¤Æ




Å·Ìî¤Ç¤¹

¤Á¤ç¤Ã¤È¹Ô¤­µÍ¤Þ¤Ã¤Æ¤·¤Þ¤Ã¤¿¤Î¤Ç¶µ¤¨¤Æ²¼¤µ¤¤¡£

Frame ¤Ë £á£ä£ä ¤·¤¿ Pane£ì ¤Î¥µ¥¤¥ºÊ¬¤À¤±»Í³Ñ¤òɽ¼¨¡¢¤Ä¤Þ¤ê Panel ¤ÎÎΰè
¤òɽ¼¨¤·¤¿¤¤¤Î¤Ç¤¹¤¬¡¢add ¤·¤¿¸å¤Ë TestPanel.paint ¤ò¸Æ¤Ö¤ÈFrame ¤Î¥µ¥¤¥º
¤ò¼èÆÀ¤·¤Æ¤·¤Þ¤¤¤Þ¤¹¡£
Panel ¥ª¥Ö¥¸¥§¥¯¥È¤ògetSize() ¤·¤Æ¤¤¤ë¤È»×¤¦¤Î¤Ç¤¹¤¬¡¢Frame ¤Î¥µ¥¤¥º
¤ò¼èÆÀ¤·¤Æ¤·¤Þ¤¦¤Î¤Ï¤Ê¤¼¤Ç¤·¤ç¤¦¡£

¤È¡¢½ñ¤¤¤Æ¤¤¤ëÅÓÃæ¤Ë²ò·è¤·¤Æ¤·¤Þ¤Ã¤¿(^^;)

¤¬¡¢¤Ê¤¼Panel ¥ª¥Ö¥¸¥§¥¯¥È¤ògetSize() ¤·¤Æ¤¤¤ë¤Ï¤º¤Ê¤Î¤Ë¡¢Frame ¤Î¥µ¥¤¥º
¤ò¼èÆÀ¤·¤Æ¤·¤Þ¤¦¤Î¤À¤í¤¦¡£

¤ó¡¼¡¢²¿¤«»×¤¤°ã¤¤¤ò¤·¤Æ¤¤¤ë¤Î¤Ç¤·¤ç¤¦¤«?


import java.awt.*;

class Test extends Frame{   
    static final int SIZE = 64;
    public static void main(String arg[]){
        
        
        Test test = new Test();
        test.setSize(200,200);
        TestPanel panel = new TestPanel();
        panel.setBounds(0,0,SIZE,SIZE);
        
        test.add(panel);        
        test.setVisible(true);
    
    }   
    public void paint(Graphics g){
    }
}
class TestPanel extends Panel{
    Dimension size;
    public TestPanel(){
        this.setSize(Test.SIZE,Test.SIZE);
        size = this.getSize();
        System.out.println("IN CONSTRACTOR IS " 
                            + "WIDTH= " + size.width 
                            + "HEIGHT= " + size.height);
    }
    public void paint(Graphics g){        
        //Dimension size = this.getSize();        // ¢«¤³¤³¤ò¥³¥á¥ó¥È¥¢¥¦
¥È¤¹¤ë¤È¤¦¤Þ¤¯¤¤¤¯¤¬¡¦¡¦
        g.drawRect(0,0,size.width-2,size.height-2);
        System.out.println("IN DRAW IS "
                            + "WIDTH= " + size.width 
                            + "HEIGHT= " + size.height);
    }
}

-- masahiro AMANO