Java AWT Dimension class

Introduction

Dimension class wraps the width and height of a component.

An object of the Dimension class is used to represent the size of a component.

// Dimension with a width and height of 200 and 20 
Dimension d  = new Dimension(200, 20); 

// Set the size of closeButton to 200 X 20. 
//Both of the statements have the same effect. 
closeButton.setSize(200, 20); /*from ww w .ja  v a 2 s  .c  o m*/
closeButton.setsize(d); 

// Get the size of closeButton 
Dimension d2 = closeButton.getSize(); 
int width = d2.width; 
int height = d2.height; 
import java.awt.Dimension;

public class Main {
  public static void main(String[] args) {
    Dimension d  = new Dimension(200, 20); 
    //from  ww  w  .  j av  a 2s .  c o  m
    System.out.println(d);
  }
}



PreviousNext

Related