UseBound1(LAB7)
import javax.swing.*;
import java.awt.*;
class UseBound1{
public static void DisplayBound(Component comp){
if(comp !=null){
Rectangle r=comp.getBounds();
System.out.println(comp.getClass().getName());
System.out.println("x coordinate:"+r.x);
System.out.println("y coordinate:"+r.y);
System.out.println("height:"+r.height);
System.out.println("width:"+r.width);
}
else return;
}
public static void main(String[]args){
JTextField text=new JTextField(10);
JButton b1=new JButton("OK");
JFrame f=new JFrame();
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
f.setSize(300,100);
Container c=f.getContentPane();
c.setLayout(new FlowLayout());
c.add(text);
c.add(b1);
f.show();
DisplayBound(b1);
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น