一個用java寫的畫圖程序(java畫圖板程序)

本文目錄一覽:

用Java編寫一個繪製圖形的小程序

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

import javax.swing.*;

//不規則圖形的繪製

public class IrregularShapeDemo extends JFrame {

GeneralPath gPath= new GeneralPath(); //GeneralPath對象實例

Point aPoint;

//構造函數

public IrregularShapeDemo() {

super(“不規則圖形的繪製”); //調用父類構造函數

enableEvents(AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK); //允許事件

setSize(300, 200); //設置窗口尺寸

setVisible(true); //設置窗口可視

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //關閉窗口時退出程序

}

public void paint(Graphics g) { //重載窗口組件的paint()方法

Graphics2D g2D = (Graphics2D)g; //獲取圖形環境

g2D.draw(gPath); //繪製路徑

}

public static void main(String[] args) {

new IrregularShapeDemo();

}

protected void processMouseEvent(MouseEvent e) { //滑鼠事件處理

if(e.getID() == MouseEvent.MOUSE_PRESSED) {

aPoint = e.getPoint(); //得到當前滑鼠點

gPath = new GeneralPath(); //重新實例化GeneralPath對象

gPath.moveTo(aPoint.x,aPoint.y); //設置路徑點

}

}

protected void processMouseMotionEvent(MouseEvent e) { //滑鼠運動事件處理

if(e.getID() == MouseEvent.MOUSE_DRAGGED) {

aPoint = e.getPoint(); //得到當前滑鼠點

gPath.lineTo(aPoint.x, aPoint.y); //設置路徑

gPath.moveTo(aPoint.x, aPoint.y);

repaint(); //重繪組件

}

}

}

求一個java程序:繪圖程序包括畫圓,橢圓,線,矩形,自定義。並且可以調圖形顏色!

public enum ShapeTypes {

LINE, CIRCLE, RECTANGLE

}

public interface Shape {

void paint(Graphics g);

}

public class Rectangle implements Shape {

// 矩形左上角的坐標

private int x, y;

// 矩形的寬度和高度

private int width, height;

private Color rectangleColor;

public Rectangle() {

super();

}

public Rectangle(int x, int y, int width, int height, Color rectangleColor) {

super();

this.x = x;

this.y = y;

this.width = width;

this.height = height;

this.rectangleColor = rectangleColor;

}

@Override

public void paint(Graphics g) {

g.setColor(rectangleColor);

g.drawRect(x, y, width, height);

}

}

public class Line implements Shape {

// 直線的起始位置

private int x1, y1;

// 直線的終止位置

private int x2, y2;

private Color lineColor;

public Line(int x1, int y1, int x2, int y2, Color lineColor) {

super();

this.x1 = x1;

this.y1 = y1;

this.x2 = x2;

this.y2 = y2;

this.lineColor = lineColor;

}

public Line() {

super();

}

@Override

public void paint(Graphics g) {

g.setColor(lineColor);

g.drawLine(x1, y1, x2, y2);

}

}

public class Circle implements Shape {

// 圓的顏色

private Color circleColor;

// 圓心的坐標

private int x, y;

// 圓的半徑

private int radius;

public Circle() {

super();

}

public Circle(int x, int y, int radius, Color circleColor) {

super();

this.circleColor = circleColor;

this.x = x;

this.y = y;

this.radius = radius;

}

@Override

public void paint(Graphics g) {

g.setColor(circleColor);

// 畫弧, 當弧的寬度和高度一致且從0~360度時就是原形了

g.drawArc(x, y, radius, radius, 0, 360);

}

}

public class SketchpadPanel extends Canvas implements MouseListener, MouseMotionListener {

private static final long serialVersionUID = -5229161042153132522L;

// 滑鼠點擊起始坐標和當前坐標

private int beginX = 0, beginY = 0, currentX = 0, currentY = 0;

// 判斷滑鼠是否被按下

private boolean isMousePressing = false;

// 保存當前的圖形, 在撤銷和恢復時使用

private final StackShape currentShapes = new StackShape();

// 保存已經刪除過的圖形

private final StackShape deletedShapes = new StackShape();

private ShapeTypes type;

private Color color;

public SketchpadPanel() {

addMouseListener(this);

addMouseMotionListener(this);

}

/**

 * 撤銷方法

 */

public void undo() {

if (currentShapes.size()  0) {

// 從所有保存過的圖形中取出最後一個, 放入到已刪除的圖形中去

Shape shape = currentShapes.pop();

deletedShapes.push(shape);

repaint();

}

}

/**

 * 恢復撤銷方法

 */

public void redo() {

if (deletedShapes.size()  0) {

// 從所有刪除的圖形中取出最後一個, 放入保存的圖形中

Shape shape = deletedShapes.pop();

currentShapes.push(shape);

repaint();

}

}

/**

 * 設置命令

 * 

 * @param type

 */

public void setShapeType(ShapeTypes type) {

this.type = type;

}

/**

 * 設置顏色

 * 

 * @param color

 */

public void setColor(Color color) {

this.color = color;

}

public void updete(Graphics g) {

paint(g);

}

/**

 * 繪製畫板

 */

@Override

public void paint(Graphics g) {

// 繪製畫板

Dimension size = getSize();

int width = size.width;

int height = size.height;

g.setColor(Color.WHITE);

g.fillRect(0, 0, width, height);

// 繪製所有圖形

Shape shape = null;

EnumerationShape e = currentShapes.elements();

while (e.hasMoreElements()) {

shape = e.nextElement();

shape.paint(g);

}

// 如果當前滑鼠沒有釋放

if (isMousePressing) {

g.setColor(color);

switch (type) {

// 繪製直線

case LINE:

g.drawLine(beginX, beginY, currentX, currentY);

break;

// 繪製矩形

case RECTANGLE:

if (currentX  beginX) {

if (currentY  beginY) {

// 如果當前位置在起始位置的左上方, 則以滑鼠當前位置為矩形的左上角位置

g.drawRect(currentX, currentY, beginX – currentX, beginY – currentY);

} else {

// 如果當前位置在起始位置的左下方, 則以滑鼠當前位置的橫坐標和起始位置的縱坐標作為矩形的左上角位置

g.drawRect(currentX, beginY, beginX – currentX, currentY – beginY);

}

} else {

if (currentY  beginY) {

// 如果當前位置在起始位置的右上方, 則以滑鼠起始位置的很坐標和當前位置的縱坐標作為矩形的左上角位置

g.drawRect(beginX, currentY, currentX – beginX, beginY – currentY);

} else {

// 如果當前位置在起始位置的右下方, 則已起始位置作為矩形的左上叫位置

g.drawRect(beginX, beginY, currentX – beginX, currentY – beginY);

}

}

break;

// 繪製圓形

case CIRCLE:

// 半徑為a*a + b*b的平方根

int radius = (int) Math

.sqrt((beginX – currentX) * (beginX – currentX) + (beginY – currentY) * (beginY – currentY));

g.drawArc(beginX – radius / 2, beginY – radius / 2, radius, radius, 0, 360);

break;

}

}

}

@Override

public void mouseClicked(MouseEvent e) {

}

@Override

public void mouseEntered(MouseEvent e) {

}

@Override

public void mouseExited(MouseEvent e) {

}

/**

 * 當滑鼠按下的時候獲得起始坐標

 */

@Override

public void mousePressed(MouseEvent e) {

beginX = e.getX();

beginY = e.getY();

isMousePressing = true;

}

/**

 * 當滑鼠釋放時獲得當前坐標

 */

@Override

public void mouseReleased(MouseEvent e) {

currentX = e.getX();

currentY = e.getY();

isMousePressing = false;

// 當釋放滑鼠時, 將繪製的圖形保存到shapes中

switch (type) {

// 繪製直線

case LINE:

Line line = new Line(beginX, beginY, currentX, currentY, color);

currentShapes.push(line);

break;

// 繪製圓形

case CIRCLE:

// 半徑為a*a + b*b的平方根

int radius = (int) Math

.sqrt((beginX – currentX) * (beginX – currentX) + (beginY – currentY) * (beginY – currentY));

Circle circle = new Circle(beginX – radius / 2, beginY – radius / 2, radius, color);

currentShapes.push(circle);

break;

// 繪製矩形

case RECTANGLE:

Rectangle rectangle = null;

if (currentX  beginX) {

if (currentY  beginY) {

rectangle = new Rectangle(currentX, currentY, beginX – currentX, beginY – currentY, color);

} else {

rectangle = new Rectangle(currentX, beginY, beginX – currentX, currentY – beginY, color);

}

} else {

if (currentY  beginY) {

rectangle = new Rectangle(beginX, currentY, currentX – beginX, beginY – currentY, color);

} else {

rectangle = new Rectangle(beginX, beginY, currentX – beginX, currentY – beginY, color);

}

}

currentShapes.push(rectangle);

break;

}

repaint();

}

@Override

public void mouseDragged(MouseEvent e) {

currentX = e.getX();

currentY = e.getY();

this.repaint();

}

@Override

public void mouseMoved(MouseEvent e) {

}

}

public class SketchpadFrame extends JFrame {

private static final long serialVersionUID = -7080053971741609904L;

private final JPanel commandPanel = new JPanel(); // 存放命令的面板

private final JPanel colorPanel = new JPanel(); // 存放顏色的面板

private final JPanel mainPanel = new JPanel(); // 主面板

private final JButton redButton = new JButton(“紅色”);

private final JButton blueButton = new JButton(“藍色”);

private final JButton greenButton = new JButton(“綠色”);

private final JButton lineButton = new JButton(“直線”);

private final JButton circleButton = new JButton(“圓”);

private final JButton rectangleButton = new JButton(“矩形”);

private final JButton undoButton = new JButton(“撤銷”);

private final JButton redoButton = new JButton(“恢復撤銷”);

private final JButton exitButton = new JButton(“退出”);

SketchpadPanel sketchPanel = new SketchpadPanel();

private void initFrame() {

commandPanel.setLayout(new FlowLayout());

commandPanel.add(lineButton);

commandPanel.add(circleButton);

commandPanel.add(rectangleButton);

commandPanel.add(undoButton);

commandPanel.add(redoButton);

commandPanel.add(exitButton);

colorPanel.setLayout(new FlowLayout());

colorPanel.add(redButton);

colorPanel.add(blueButton);

colorPanel.add(greenButton);

mainPanel.setLayout(new BorderLayout());

mainPanel.add(commandPanel, BorderLayout.NORTH);

mainPanel.add(colorPanel, BorderLayout.CENTER);

getContentPane().add(“South”, mainPanel);

getContentPane().add(“Center”, sketchPanel);

// 初始化設置:顏色和命令

lineButton.setForeground(Color.RED);

sketchPanel.setColor(Color.RED);

redButton.setForeground(Color.RED);

sketchPanel.setShapeType(ShapeTypes.LINE);

}

private void initListener() {

redButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

redAction(e);

}

});

blueButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

blueAction(e);

}

});

greenButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

greenAction(e);

}

});

undoButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

undoAction(e);

}

});

redoButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

redoAction(e);

}

});

exitButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

exitAction(e);

}

});

lineButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

lineAction(e);

}

});

circleButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

circleAction(e);

}

});

rectangleButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

rectangleAction(e);

}

});

}

public SketchpadFrame() {

initFrame();

initListener();

this.setSize(500, 600);

setLocationByPlatform(true);

setResizable(true);

}

/* ********************處理事件********************* */

private void undoAction(ActionEvent e) {

sketchPanel.undo();

}

private void redoAction(ActionEvent e) {

sketchPanel.redo();

}

private void exitAction(ActionEvent e) {

System.exit(0);

}

private void lineAction(ActionEvent e) {

// 選中按鈕為紅色, 其餘為黑色

lineButton.setForeground(Color.RED);

circleButton.setForeground(Color.BLACK);

rectangleButton.setForeground(Color.BLACK);

sketchPanel.setShapeType(ShapeTypes.LINE);

}

private void circleAction(ActionEvent e) {

circleButton.setForeground(Color.RED);

lineButton.setForeground(Color.BLACK);

rectangleButton.setForeground(Color.BLACK);

sketchPanel.setShapeType(ShapeTypes.CIRCLE);

}

private void rectangleAction(ActionEvent e) {

rectangleButton.setForeground(Color.RED);

lineButton.setForeground(Color.BLACK);

circleButton.setForeground(Color.BLACK);

sketchPanel.setShapeType(ShapeTypes.RECTANGLE);

}

private void redAction(ActionEvent e) {

redButton.setForeground(Color.RED);

blueButton.setForeground(Color.BLACK);

greenButton.setForeground(Color.BLACK);

sketchPanel.setColor(Color.RED);

}

private void blueAction(ActionEvent e) {

blueButton.setForeground(Color.RED);

redButton.setForeground(Color.BLACK);

greenButton.setForeground(Color.BLACK);

sketchPanel.setColor(Color.BLUE);

}

private void greenAction(ActionEvent e) {

greenButton.setForeground(Color.RED);

redButton.setForeground(Color.BLACK);

blueButton.setForeground(Color.BLACK);

sketchPanel.setColor(Color.GREEN);

}

}

/**

 * 

 * @author 不落的太陽(Sean Yang)

 * @version 1.0

 * @since JDK 1.8

 * 

 */

public class SketchpadMain {

/**

 * 測試方法

 * 

 * @param args命令行參數

 */

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

@Override

public void run() {

JFrame frame = new SketchpadFrame();

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

});

}

}

java 繪圖程序

我基於你原來畫圖的方法,添加了事件觸發的命令b[j].setActionCommand(“b” + j);否則你不能在事件響應處理的方法中使用e.getActionCommand(),而且字元串的比較用equals方法比較好。現在可以運行了,你可以看一下:

import java.applet.Applet;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class drawing extends Applet implements ActionListener {

Button b[] = new Button[5];

String fontname = “仿宋_GB2312”;

int style = Font.PLAIN;

int size = 24;

int index = 0;

Font myfont;

public void init() {

setSize(700,700);

myfont = new Font(fontname, style, size);

b[0] = new Button(“扇形”);

b[1] = new Button(“圓形”);

b[2] = new Button(“三角形”);

b[3] = new Button(“長方形”);

b[4] = new Button(“橢圓形”);

for (int j = 0; j b.length; j++) {

b[j].setBounds(10, 10, 50, 20);

b[j].addActionListener(this);

b[j].setActionCommand(“b” + j);

add(b[j]);

}

}

public void actionPerformed(ActionEvent e) {

if (e.getActionCommand().equals(“b0”)) {

index = 0;

repaint();

}

if (e.getActionCommand().equals(“b1”)) {

index = 1;

repaint();

}

if (e.getActionCommand().equals(“b2”)) {

index = 2;

repaint();

}

if (e.getActionCommand().equals(“b3”)) {

index = 3;

repaint();

}

if (e.getActionCommand().equals(“b4”)) {

index = 4;

repaint();

}

}

public void paint(Graphics g) {

switch (index) {

case 0:

g.fillArc(0, 60, 80, 60, 30, 120);

break;

case 1:

g.drawOval( 300, 50, 60, 60);

break;

case 2:

Polygon filledPolygon = new Polygon();

filledPolygon.addPoint(380, 50);

filledPolygon.addPoint(380, 110);

filledPolygon.addPoint(450, 90);

g.drawPolygon(filledPolygon);

break;

case 3:

g.drawRect( 200, 50, 80, 60);

break;

case 4:

g.drawOval(100, 50, 80, 60);

break;

default:

g.fillArc(0, 60, 80, 60, 30, 120);

break;

}

}

/*

* public void paint(Graphics g) { g.fillArc( 0, 60, 80, 60, 30, 120);

* //繪製扇形 g.drawOval( 100, 50, 80, 60); g.drawRect( 200, 50, 80, 60);

* g.drawOval( 300, 50, 60, 60); Polygon filledPolygon=new Polygon();

* filledPolygon.addPoint(380,50); filledPolygon.addPoint(380,110);

* filledPolygon.addPoint(450,90); g.drawPolygon(filledPolygon); }

*/

}

用java編寫一個簡單的畫圖程序。不用複雜

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

import javax.swing.*;

//不規則圖形的繪製

public class IrregularShapeDemo extends JFrame {

GeneralPath gPath= new GeneralPath(); //GeneralPath對象實例

Point aPoint;

//構造函數

public IrregularShapeDemo() {

super(“不規則圖形的繪製”); //調用父類構造函數

enableEvents(AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK); //允許事件

setSize(300, 200); //設置窗口尺寸

setVisible(true); //設置窗口可視

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //關閉窗口時退出程序

}

public void paint(Graphics g) { //重載窗口組件的paint()方法

Graphics2D g2D = (Graphics2D)g; //獲取圖形環境

g2D.draw(gPath); //繪製路徑

}

public static void main(String[] args) {

new IrregularShapeDemo();

}

protected void processMouseEvent(MouseEvent e) { //滑鼠事件處理

if(e.getID() == MouseEvent.MOUSE_PRESSED) {

aPoint = e.getPoint(); //得到當前滑鼠點

gPath = new GeneralPath(); //重新實例化GeneralPath對象

gPath.moveTo(aPoint.x,aPoint.y); //設置路徑點

}

}

protected void processMouseMotionEvent(MouseEvent e) { //滑鼠運動事件處理

if(e.getID() == MouseEvent.MOUSE_DRAGGED) {

aPoint = e.getPoint(); //得到當前滑鼠點

gPath.lineTo(aPoint.x, aPoint.y); //設置路徑

gPath.moveTo(aPoint.x, aPoint.y);

repaint(); //重繪組件

}

}

}

用Java一個簡單的畫圖程序

下面是我以前做的小程序,希望能給你點幫助!

package menu;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class DaYin extends JFrame implements ActionListener{

public DaYin() {

Container c=this.getContentPane();

c.setLayout(new BorderLayout());

JMenuBar jmb=new JMenuBar();

JMenu jm=null;

jm=new JMenu(“文件”);

jmb.add(jm);

jm=new JMenu(“編輯”);

jmb.add(jm);

jm=new JMenu(“列印”);

JMenuItem jmi=new JMenuItem(“列印預覽”);

jmi.addActionListener(this);

jm.add(jmi);

jmb.add(jm);

jm=new JMenu(“幫助”);

jmb.add(jm);

this.setJMenuBar(jmb);

this.setSize(1024,768);

this.setVisible(true);

this.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

System.exit(0);

}

});

}

public static void main(String[] args) {

new DaYin();

}

public void update(Graphics g){

g.setColor(Color.black);

String title[]={“摘要”,”科目”,”子目或戶名”,”借方金額”,”貸方金額”};

String danwei[]={“千”,”百”,”十”,”萬”,”千”,”百”,”十”,”元”,”角”,”分”};

int csx=200;//列印x的初始坐標

int csy=200;//列印y的初始坐標

int x=csx;

int y=csy;

int a=x+20;//列印字體x的初始坐標

int b=y+20;//列印字體y的初始坐標

int row=7;//一共列印出幾條橫線

int cul=5;//一共列印出幾條豎線

int hangju=30;//線與線之間的縱向間距

int lieju=100;//線與線之間的橫向間距

int yy=hangju*row+y;

int c=yy+20;

g.setFont(new Font(“行楷”,Font.TYPE1_FONT,24));

g.drawString(“記 賬 憑 證”, x+160, y-40);//列印出記賬憑證這幾個字

g.drawLine(x+100, y-30, x+340, y-30);//列印出記賬憑證下面的那條線

g.setFont(new Font(“行楷”,Font.TYPE1_FONT,13));

g.drawString(“年 月 日 第_______號”, x+260, y-10);

//g.drawLine(x+430, y-10, x+470, y-10);

for(int i=0;i=row;i++){

g.drawLine(x, y, cul*lieju+x+25, y);//此循環用於畫出表格的行

if(i==0)

y+=hangju*2;

else

y+=hangju;

}

y=csy;

g.drawLine(x+lieju*3, y+hangju, cul*lieju+x, y+hangju);//列印出第一行半的橫線

for(int j=0;j=cul;j++){

g.drawLine(x, y, x, row*hangju+y);//此循環用於畫出表格的列

x+=lieju;

}

x=csx;

for(int z=0;zcul;z++){

g.setColor(Color.red);//設置顏色

g.setFont(new Font(“”,Font.TYPE1_FONT,13));//設置表頭字體

if(z3)

g.drawString(title[z], a, b+hangju/2);

else

g.drawString(title[z], a, b);//為表格添加表頭

a+=lieju;

}//76-89列印出一個表格形狀

int xx=lieju*3+x+10;

for(int v=0;v=9;v++){

g.drawLine(xx, y+hangju, xx, row*hangju+y+hangju);//此循環用於畫出表格的列

g.setFont(new Font(“”,Font.TYPE1_FONT,11));

g.drawString(danwei[v], xx-10, y+hangju+20);//為表格添加表頭

if(v%2==0)

g.setColor(Color.red);//設置顏色

else

g.setColor(Color.BLUE);//設置顏色

xx+=10;

}

for(int n=0;n9;n++){

g.drawLine(xx, y+hangju, xx, row*hangju+y+hangju);//此循環用於畫出表格的列

g.drawString(danwei[n],xx-10, y+hangju+20);//為表格添加表頭

if(n%2==0)

g.setColor(Color.red);//設置顏色

else

g.setColor(Color.BLUE);//設置顏色

xx+=10;

}

g.drawString(danwei[9],xx-10, y+hangju+20);

g.setColor(Color.black);//設置顏色

for(int i=0;i=1;i++){

g.drawLine(x,yy , cul*lieju+x, yy);//此循環用於畫出表格的行

yy+=hangju;

}

yy=hangju*row+y;

for(int j=0;j=3;j++){

g.drawLine(x, yy, x, (row+1)*hangju+y);//此循環用於畫出表格的列

if(j0){

x+=lieju;

}else{

x+=lieju*3;

}

}//112-128列印出表格的最後一行單元格

x=csx;

g.setFont(new Font(“”,Font.TYPE1_FONT,13));

g.drawString(“合 計”,x+60, c);

g.drawString(“會計主管 記賬 出納 審核 制證”, x+30, yy+50);

g.drawLine(cul*lieju+x+25, y, cul*lieju+x+25, (row+1)*hangju+y);//列印出最後一列

g.drawString(“記”,cul*lieju+x+6, y+15);

g.drawString(“賬”, cul*lieju+x+6, y+35);

g.drawString(“√”, cul*lieju+x+6, y+55);//134-136為最後一列寫入字體

g.drawString(“附”,cul*lieju+x+35, y+75);

g.drawString(“件”, cul*lieju+x+35, y+95);

g.drawString(“張”, cul*lieju+x+35, y+175);//134-136為最後一列後寫入字體

}

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(e.getActionCommand().equals(“列印預覽”)){

this.repaint();

}

}

}

使用drawLine()做了一個記賬憑證。

執行點擊”列印”子菜單”列印預覽”就可顯示出我們所畫的”記賬憑證表”

希望這個小程序能夠給你點靈感

請高手幫忙完善簡單的java畫圖程序

你的這個程序是Applet

對於applet應用程序,可以用下面的方法運行:

1、javac Paint.java後生成Paint.class

2、在跟Paint.class同一級的目錄下新建一個文本文件,並輸入:

applet code=”Paint.class”

width=320 height=180

/applet

3、保存並將文件名改為Paint.html (這個html文件的名字任意)

4、在cmd中輸入appletviewer Paint.html便可以看見你的applet了

原創文章,作者:YFTB,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/144995.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
YFTB的頭像YFTB
上一篇 2024-10-26 11:54
下一篇 2024-10-26 11:54

相關推薦

  • Java JsonPath 效率優化指南

    本篇文章將深入探討Java JsonPath的效率問題,並提供一些優化方案。 一、JsonPath 簡介 JsonPath是一個可用於從JSON數據中獲取信息的庫。它提供了一種DS…

    編程 2025-04-29
  • java client.getacsresponse 編譯報錯解決方法

    java client.getacsresponse 編譯報錯是Java編程過程中常見的錯誤,常見的原因是代碼的語法錯誤、類庫依賴問題和編譯環境的配置問題。下面將從多個方面進行分析…

    編程 2025-04-29
  • Java騰訊雲音視頻對接

    本文旨在從多個方面詳細闡述Java騰訊雲音視頻對接,提供完整的代碼示例。 一、騰訊雲音視頻介紹 騰訊雲音視頻服務(Cloud Tencent Real-Time Communica…

    編程 2025-04-29
  • Java Bean載入過程

    Java Bean載入過程涉及到類載入器、反射機制和Java虛擬機的執行過程。在本文中,將從這三個方面詳細闡述Java Bean載入的過程。 一、類載入器 類載入器是Java虛擬機…

    編程 2025-04-29
  • python強行終止程序快捷鍵

    本文將從多個方面對python強行終止程序快捷鍵進行詳細闡述,並提供相應代碼示例。 一、Ctrl+C快捷鍵 Ctrl+C快捷鍵是在終端中經常用來強行終止運行的程序。當你在終端中運行…

    編程 2025-04-29
  • Python程序需要編譯才能執行

    Python 被廣泛應用於數據分析、人工智慧、科學計算等領域,它的靈活性和簡單易學的性質使得越來越多的人喜歡使用 Python 進行編程。然而,在 Python 中程序執行的方式不…

    編程 2025-04-29
  • Java Milvus SearchParam withoutFields用法介紹

    本文將詳細介紹Java Milvus SearchParam withoutFields的相關知識和用法。 一、什麼是Java Milvus SearchParam without…

    編程 2025-04-29
  • Python程序文件的拓展

    Python是一門功能豐富、易於學習、可讀性高的編程語言。Python程序文件通常以.py為文件拓展名,被廣泛應用於各種領域,包括Web開發、機器學習、科學計算等。為了更好地發揮P…

    編程 2025-04-29
  • Java 8中某一周的周一

    Java 8是Java語言中的一個版本,於2014年3月18日發布。本文將從多個方面對Java 8中某一周的周一進行詳細的闡述。 一、數組處理 Java 8新特性之一是Stream…

    編程 2025-04-29
  • Java判斷字元串是否存在多個

    本文將從以下幾個方面詳細闡述如何使用Java判斷一個字元串中是否存在多個指定字元: 一、字元串遍歷 字元串是Java編程中非常重要的一種數據類型。要判斷字元串中是否存在多個指定字元…

    編程 2025-04-29

發表回復

登錄後才能評論