导航:首页 > 编程语言 > 图形类java

图形类java

发布时间:2022-09-25 04:08:52

java中的图形类组件按组成关系可以分为哪几类

Java 平台有三个版本,这使软件开发人员、服务提供商和设备生产商可以针对特定的市场进行开发:

* Java SE(Java Platform,Standard Edition)。Java SE 以前称为 J2SE。它允许开发和部署在桌面、服务器、嵌入式环境和实时环境中使用的 Java 应用程序。Java SE 包含了支持 Java Web 服务开发的类,并为 Java Platform,Enterprise Edition(Java EE)提供基础。
* Java EE(Java Platform,Enterprise Edition)。这个版本以前称为 J2EE。企业版本帮助开发和部署可移植、健壮、可伸缩且安全的服务器端 Java 应用程序。Java EE 是在 Java SE 的基础上构建的,它提供 Web 服务、组件模型、管理和通信 API,可以用来实现企业级的面向服务体系结构(service-oriented architecture,SOA)和 Web 2.0 应用程序。
* Java ME(Java Platform,Micro Edition)。这个版本以前称为 J2ME。Java ME 为在移动设备和嵌入式设备(比如手机、PDA、电视机顶盒和打印机)上运行的应用程序提供一个健壮且灵活的环境。Java ME 包括灵活的用户界面、健壮的安全模型、许多内置的网络协议以及对可以动态下载的连网和离线应用程序的丰富支持。基于 Java ME 规范的应用程序只需编写一次,就可以用于许多设备,而且可以利用每个设备的本机功能。

㈡ 用JAVA写一个简单图形类

package com.qzd.swing.security;import javax.swing.*;import com.qzd.swing.io.IOUtils;
import com.qzd.swing.security.util.CipherUtils;import java.awt.Rectangle;
import java.awt.Font;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;public class MyDecrypt extends JFrame { private static final long serialVersionUID = 1144364976994226418L; public MyDecrypt() {
super("DES 解密");
init(); } private JLabel pathLabel;
private JTextField filePathField;
private JButton fileChooserButton;
private JTextArea originalArea;
private JLabel originalTextLabel;
private JLabel decryptLabel;
private JTextArea decryptArea;
private JButton saveButton;
private JButton decryptButton;
private JScrollPane scrollPaneOne;
private JScrollPane scrollPaneTwo; private JFileChooser fc; public static void main(String[] args) {
new MyDecrypt();
} private void init() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(null);
setSize(580, 600);
creatComponent();
setMyFont();
addComponents();
setMyBounds();
addListener();
//System.out.println(Charset.defaultCharset());
this.setVisible(true);
} public void addListener() {
MyDecryptActionListener my = new MyDecryptActionListener(this);
fileChooserButton.addActionListener(my);
decryptButton.addActionListener(my);
saveButton.addActionListener(my);
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == fileChooserButton) {
int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
filePathField.setText(file.getPath());
originalArea.setText(IOUtils.inputFileISO(file)); }
} else if (e.getSource() == decryptButton) { String password = JOptionPane.showInputDialog(this, "请输入口令进行解密:");
byte bytes[] = null;
try {
bytes = CipherUtils.decrypt(password,
"12345678".getBytes(), originalArea.getText().getBytes("ISO8859-1"));
decryptArea.setText(new String(bytes,"GBK"));
JOptionPane.showMessageDialog(this, "恭喜你解密成功!!");
} catch (UnsupportedEncodingException e1) {

e1.printStackTrace();
}
} else if (e.getSource() == saveButton) {
int returnVal = fc.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
IOUtils.outputFile(decryptArea.getText(), file.getPath());
JOptionPane.showMessageDialog(MyDecrypt.this, "恭喜你!!"
+ file.getPath() + "成功保存", "提示信息",
JOptionPane.WARNING_MESSAGE);
}
}
} private void addComponents() {
add(pathLabel);
add(filePathField);
add(fileChooserButton);
add(originalTextLabel);
add(decryptLabel);
add(saveButton);
add(decryptButton);
add(scrollPaneOne);
add(scrollPaneTwo); } private void setMyBounds() {
pathLabel.setBounds(new Rectangle(8, 14, 70, 31));
saveButton.setBounds(new Rectangle(235, 495, 94, 29));
decryptLabel.setBounds(new Rectangle(235, 282, 108, 29));
originalTextLabel.setBounds(new Rectangle(246, 49, 93, 35));
scrollPaneTwo.setBounds(new Rectangle(12, 321, 554, 164));
scrollPaneOne.setBounds(new Rectangle(11, 92, 555, 176));
fileChooserButton.setBounds(new Rectangle(442, 14, 83, 29));
filePathField.setBounds(new Rectangle(97, 14, 321, 30));
} public void setMyFont() {
pathLabel.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
decryptButton.setBounds(new Rectangle(460, 281, 104, 31));
decryptLabel.setFont(new java.awt.Font("宋体", Font.PLAIN, 25));
originalTextLabel.setFont(new java.awt.Font("宋体", Font.PLAIN, 25));
} public void creatComponent() {
pathLabel = new JLabel("文件路径");
filePathField = new JTextField();
fileChooserButton = new JButton("文件", createImageIcon("Open16.gif"));
originalArea = new JTextArea();
originalTextLabel = new JLabel("原文");
decryptLabel = new JLabel("解密后");
decryptArea = new JTextArea();
saveButton = new JButton("保存", createImageIcon("Save16.gif"));
decryptButton = new JButton("点击解密");
scrollPaneOne = new JScrollPane(originalArea);
scrollPaneTwo = new JScrollPane(decryptArea);
fc = new JFileChooser();
} protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = MyEncrypt.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}}class MyDecryptActionListener implements ActionListener {
private MyDecrypt myDecrypt; public MyDecryptActionListener(MyDecrypt myDecrypt) {
this.myDecrypt = myDecrypt;
} public void actionPerformed(ActionEvent e) {
myDecrypt.actionPerformed(e); }} //自己看下吧 我做的一个简单的加密程序

㈢ JAVA编程题:设计三个图形类

真不知道这是考写代码还是考数学。
给你一个思路吧,定义一个抽象类表示图形,有颜色属性、粗细属性、求面积方法、比较大小的方法。
然后在定义一个类表示三角形,继承这个抽象类,三角形类有三个属性,分别表示它的三个顶点坐标。
也定义一个类表示矩形,继承抽象类,它有两个属性,分别表示它左上角和右下角的坐标。
再定义一个类表示圆形,它有两个属性,分别表示圆心和圆上任一点的坐标。

㈣ Java程序设计图形类

public class Rectangle{ private int width; private int height; public Rectangle(){ this.width = 10; this.height = 10; } public Rectangle(int width, int height){ this.width = width; this.height = height; } public int area(){ return width * height; } //省略getter/setter }

㈤ java设计图形(Shape)类及其子类(Circle、Rectangle)

你好,刚好闲着帮你写一个:
Shape类:
public class Shape {

protected Point location;
public Shape(){

}
public double area(){
return 0.0;
}

}
Circle类:
public class Circle extends Shape{
private int r;
public Circle() {

}
public Circle(Point center,int r) {
super.location=center;
this.r = r;
}
public double area() {

return Math.PI*r*r ;
}
}
Rectangle类:
public class Rectangle extends Shape{
private int width;
private int height;
public Rectangle() {

}
public Rectangle(Point o,int width, int height) {
location=o;

this.width = width;
this.height = height;
}
public double area() {

return width*height;
}

}
我这里图方便,在创建圆的时候直接用圆心和半径创建,还有矩形也是用一个点位置和长宽创建,所以还要加一个点类:
public class Point {

public int x;
public int y;

public Point() {
}

public Point(int x, int y) {
this.x = x;
this.y = y;
}
}

㈥ java编写图形抽象类(Shape)

我来写一下吧:
abstract class Shape{
private double c;
private double s;
public abstract void girth();
public abstract void area();
public void setGirth(double c){
this.c = c;
}
public void setArea(double s){
this.s = s;
}
public double getGirth(){
return c;
}
public double getArea(){
return s;
}
public void outInfo(){}
}
class Circle extends Shape{
private static final double PI = 3.1415926;
private double r;
//定义一个构造函数
public Circle(double r){
this.r = r;
}
//重写抽象方法
public void girth() {
double a =2*PI*r;
super.setGirth(a);
}
public void area() {
double b =PI*r*r;
super.setArea(b);
}
public void outInfo() {
this.girth();
this.area();
System.out.println("所求圆形周长为:"+super.getGirth());
System.out.println("所求圆形面积为:"+super.getArea());
}
}
class Rectangle extends Shape{
private double height;
private double width;
//定义一个构造函数
public Rectangle(double height,double width){
this.height = height;
this.width = width;
}
//重写抽象方法
public void girth() {
double a =2*(height+width);
super.setGirth(a);
}
public void area() {
double b =(height*width);
super.setArea(b);
}
public void outInfo() {
this.girth();
this.area();
System.out.println("所求矩形周长为:"+super.getGirth());
System.out.println("所求矩形面积为:"+super.getArea());
}
}
class Triangle extends Shape{
private double lengthA;
private double lengthB;
private double lengthC;
//定义一个构造函数
public Triangle(double lengthA,double lengthB,double lengthC){
this.lengthA = lengthA;
this.lengthB = lengthB;
this.lengthC = lengthC;
}
//重写抽象方法
public void girth() {
double a =(lengthA+lengthB+lengthC);
super.setGirth(a);
}
public void area() {
if((lengthA+lengthB < lengthC) || (lengthA + lengthC < lengthB) || (lengthB+lengthC < lengthA)) {
System.out.println("两边之和必须大于第三个边");
System.exit(0);
}
double p = (lengthA+lengthB+lengthC)/2;
double b = Math.sqrt(p*(p-lengthA)*(p-lengthB)*(p-lengthC));
super.setArea(b);
}
public void outInfo() {
this.girth();
this.area();
System.out.println("所求三角形周长为:"+super.getGirth());
System.out.println("所求三角形面积为:"+super.getArea());
}
}
public class ShapeTest {
public static void main (String [] args){
Shape circle = new Circle(3.0);
Shape rectangle = new Rectangle(8.0,7.0);
Shape triangle = new Triangle(3.0,4.0,5.0);

circle.outInfo();
rectangle.outInfo();
triangle.outInfo();
}
}

㈦ java图形类是什么

java 图形类库常见的有 swing 和 swt,这两个用的比较多些,像着名的开源工具 eclipse 就是 swt开发的。
如果你问得是画图的类的吧,一般是Graphics2D

㈧ 用java编写一个图形类,该类具有长和高属性,具有求面积的方法

//长方形
classRetangleextendsGraph{
@Override
publicintsquare(){
returngetHeight()*getWidth();
}
}
//三角
//这里默认长度是底的长度
classTriangleextendsGraph{
@Override
publicintsquare(){
return(getHeight()*getWidth())/2;
}
}
//图形
abstractclassGraph{
privateintheight;
privateintwidth;

publicabstractintsquare();

publicintgetHeight(){
returnheight;
}

publicvoidsetHeight(intheight){
this.height=height;
}

publicintgetWidth(){
returnwidth;
}

publicvoidsetWidth(intwidth){
this.width=width;
}
}
publicclassTest{
publicstaticvoidmain(String[]args){
Graphg=newRetangle();
g.setHeight(2);
g.setWidth(3);
System.out.println("长方形的面积是:"+g.square());
Graphg1=newTriangle();
g1.setHeight(2);
g1.setWidth(3);
System.out.println("三角形的面积是:"+g1.square());
}
}

㈨ Java图形类模拟

packagecom.;

publicclassCircle{
privateintradius; //圆半径
privatedoublearea; //圆面积
publicfinaldoublePI=3.14; //常量

publicCircle(){

}

publicCircle(intradius,doublearea){
this.radius=radius;
this.area=area;
}

publicdoublegetArea(intradius){
returnPI*radius*radius;
}


publicintgetRadius(){
returnradius;
}

publicvoidsetRadius(intradius){
this.radius=radius;
}
}


package com.;


import com..Circle;


public class Cylinder extends Circle{

protected double h; //高


public double getH() { //获取高

return h;

}


public void setH(double h) { //设置高

this.h = h;

}

public double getArea(int radius){

return h*PI*radius*radius;

}

}

packagecom.test;

importcom..Circle;
importcom..Cylinder;

publicclassTest{
publicstaticvoidmain(String[]args){
Circlec=newCircle();
c.setRadius(3);
System.out.println("圆面积"+c.getArea(c.getRadius()));

Cylindercy=newCylinder();
cy.setRadius(6);
cy.setH(3);
System.out.println(cy.getRadius());
doublecarea=cy.getArea(cy.getRadius());
System.out.println("圆柱体体积:"+carea);
}
}

阅读全文

与图形类java相关的资料

热点内容
穿搭技巧app卡色配什么颜色 浏览:589
程序员得结石 浏览:124
查公司薪资的app叫什么 浏览:407
压缩包多个文件夹图片连续看 浏览:480
linuxmysql无法用命令启动 浏览:439
地税身份认证用什么ApP 浏览:529
网址加密后能防止被封网吗 浏览:759
pic单片机项目 浏览:177
oppo手机忘记加密密码忘了怎么办 浏览:151
算法竞赛入门经典代码 浏览:155
多功能防盗加密锁闭阀 浏览:862
遥控灯单片机 浏览:813
网络时间同步算法 浏览:473
单片机p1口怎么检测 浏览:913
pdf高亮颜色 浏览:322
银行程序员的工资多少 浏览:19
服务器如何使用移动硬盘 浏览:533
pc饥荒为什么没有服务器 浏览:442
阿里云服务器地址是什么 浏览:148
如何戒除网瘾app 浏览:955