Java中dimension类详解
dimension - Java的⼀个类
dimension是Java的⼀个类,封装了⼀个构件的⾼度和宽度,这个类与⼀个构件的许多属性具有相关性,因此在Component类中定义多个与之有关的⽅法,LayoutManager接⼝也与⼀个Dimension对象有关联。Dimension类的⾼度和宽度值是⼀个整数,表明有多少个像素点。
与Dimension类相关⽅法:getSize()和setSize(Dimension size)。分别⽤来获得和设置⽅格的⼤⼩。
下⾯介绍类dimension的构造⽅法。
构造函数
初始化的新实例类使⽤的默认值。
初始化的新实例类使⽤的名称。
初始化的新实例类使⽤的名称和标识符。
⽅法
(以下的⽅法常⽤的会⽤符号标识,注意侧重点)
将 对象添加到指定的容器。 Adds a object to the specified container.
(Inherited from )
在添加指定的索引后,显⽰ 对象。 Displays a object after added to the specified index.
(Inherited from )
在移动指定的索引后,显⽰ 对象。 Displays a object after moving to the specified index.
(Inherited from )
删除 对象后,显⽰ 。 Displays a after a object is removed.
(Inherited from )
清除前删除 对象。 Removes the object before the cleanup.
(Inherited from )
向服务器发送⼀个处理类型,并指⽰对于 对象是否可执⾏该处理类型。 Sends a processing type to the server and indicates whether that process type can take place for the object.
创建 对象的全新完整副本。 Creates a new, full copy of a object.
创建 对象的新副本。 Creates a new copy of the object.
(Inherited from )
副本到指定的对象的对象。 Copies a object to the specified object.
将该对象复制到指定⽬标。 Copies the object to the specified destination.
(Inherited from )
副本到指定的对象的对象。 Copies a object to the specified object.
(Inherited from )
副本到指定的对象的对象。 Copies a object to the specified object.
(Inherited from )
删除当前对象并更新服务器。 Removes current object and updates server.
(Inherited from )
使⽤指定选项删除当前对象并更新服务器。 Removes current object and updates server using specified options.
(Inherited from )
(Inherited from )
使⽤指定选项删除当前对象并更新服务器。 Removes current object and updates server using specified options. 对指定的warnings 对象返回了由删除操作引发的警告。 Warnings resulting from drop operation are returned on the specified warnings object.
(Inherited from )
使⽤指定选项删除当前对象并更新服务器。 Removes current object and updates server using specified options. 对指定的warnings 变量返回了由删除操作引发的警告,并且对指定的 impactResult 变量返回了操作中受影响对象的结果。 Warnings resulting from drop operation are returned on the sp
ecified warnings variable and results for affected objects in operation are returned on specified impactResult variable.
(Inherited from )
使⽤指定选项删除当前对象并更新服务器。 Removes current object and updates server using specified options. 对指定的warnings 变量返回了由删除操作引发的警告,并且对指定的 impactResult 变量返回了操作中受影响对象的结果。 Warnings resulting from drop operation are returned on the specified warnings variable and results for affected objects in operation are returned on specified impactResult variable.
(Inherited from )
获取 以创建引⽤。 Gets a to create references.
(Inherited from )
将挖掘结构和后续依赖项添加到指定Hashtable。 Adds the mining structures and subsequent dependents to the specified Hashtable.
获取删除依赖关系。 Gets the drop dependents.
(Inherited from )
获取该维度引⽤的对象。 Gets the objects that the dimension references.
获取覆盖更新的 的 对象。 Gets the object that overwrites the updated .
(Inherited from )
进程。 Processes the .
(Inherited from )
其实上⾯的⽅法⼤部分都⽤不到,需要的时候可以查阅
下⾯以⼀个例⼦来简单使⽤⼀下介绍⼀下dimension的使⽤
(使⽤⼀个远程控制的⼈⼯智能程序来描述(仅部分代码,加粗倾斜部分代码为使⽤实例))
package zzh;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class LocationScreen {
public static void main(String[] args) {
System.out.println("这是⼀个请求远程控制桌⾯的⼈⼯智能程序");
//询问框
int choic = JOptionPane.showConfirmDialog(null,"请求控制对⽅电脑?","私⼈专属定制",JOptionPane.YES_NO_OPTION);        //返回值为什么是int,
if(choic == JOptionPane.NO_OPTION){
return;
}
//输⼊IP地址和端⼝号,IP就是到是那台电脑,⽽端⼝号是确定那⼀台电脑
JOptionPane.showInputDialog("请输⼊IP地址和端⼝号","127.0.0.1:20000");
//初始化窗⼝
JFrame jFrame = new JFrame("远程监控");
jFrame.setSize(500,600);
jFrame.setVisible(true);
jFrame.setAlwaysOnTop(true);
jFrame.setLocationRelativeTo(null);
jFrame.setDefaultCloseOperation(jFrame.EXIT_ON_CLOSE);
//定义⼀个⽅法获取本机的操作系统
Toolkit kt = DefaultToolkit();
//⽬的是获取屏幕的尺⼨,毕竟电脑型号不⼀样
Dimension dm = kt.getScreenSize();
//这⾏代码和下⾯的代码实现效果是⼀样的
System.out.width(),dm.getheight());object to
//不过是⼀个调⽤了具体的⽅法
System.out.println(dm);
//设置⼀个显⽰的内容
JLabel jLabel = new JLabel();
jFrame.add(jLabel);
//创建⼀个机器⼈
try {
Robot robot = new Robot();
//指定坐标,⽬的是获取整个电脑界⾯的图⽚(视频就是⼀帧帧的图⽚)
new Width(), 0, (Width()-Width(), (Height());
} catch (Exception e) {
e.printStackTrace();
}
}
}
具体⽅法
关于具体实现可以参照API⽂档,这⾥不再赘述。
如有错误,请多多指正(虽然我也不认为有什么错)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。