㈠ 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);
}
}