手机上绘图的java代码,手机上绘图的java代码怎么用

java绘图,求代码

上代码:

汉阳ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.FlowLayout;

import java.awt.Graphics;

import java.awt.Image;

import java.awt.LayoutManager;

import java.awt.Paint;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

import java.awt.event.*;

public class YuanYiDong extends JFrame{

private static int BANJIN=0;

private static int X=0;

private static int Y=0;

JTextField rTxt=new JTextField(5);

JTextField xField=new JTextField(5);

JTextField yField=new JTextField(5);

JButton paintBt=new JButton("画");

JLabel huaban=new huaban();

JPanel jPanel=new JPanel();

JLabel banjingLabel,xLabel,yLabel;

public YuanYiDong(){

banjingLabel=new JLabel("半径");

xLabel=new JLabel("X坐标");

yLabel=new JLabel("Y坐标");

this.setTitle("圆的移动");

this.setLocation(300,100);

this.setSize(500, 400);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true);

this.add(rTxt);

jPanel.setLayout(new FlowLayout());

add(huaban,BorderLayout.CENTER);

jPanel.add(banjingLabel);

jPanel.add(rTxt);

jPanel.add(xLabel);

jPanel.add(xField);

jPanel.add(yLabel);

jPanel.add(yField);

jPanel.add(paintBt);

add(jPanel,BorderLayout.NORTH);

paintBt.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

BANJIN=Integer.parseInt(rTxt.getText());

X=Integer.parseInt(xField.getText());

Y=Integer.parseInt(yField.getText());

huaban.repaint();

}

});

}

private void drawCirlce(Graphics g) {

g.setColor(Color.blue);

g.fillOval(X, Y, BANJIN,BANJIN);

}

public static void main(String[] args) {

YuanYiDong frame = new YuanYiDong();

}

public class huaban extends JLabel{

public huaban(){}

public void paint(Graphics g) {

Image image = createImage(getWidth(), getHeight());

drawCirlce(image.getGraphics());

g.drawImage(image, 0, 0, null);

}

}

}

给分吧!

用java编写绘图工具的代码

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

public class ResponseToMouse extends Applet implements ActionListener,MouseListener,MouseMotionListener

{

int xPos,yPos,k=0;

Button btnDraw,btnClean,btnErase;

public void init()

{

btnDraw = new Button("画图");

btnClean = new Button("清屏");

btnErase = new Button("擦除");

add(btnDraw);

add(btnClean);

add(btnErase);

btnDraw.addActionListener(this);

btnClean.addActionListener(this);

btnErase.addActionListener(this);

addMouseListener(this);

addMouseMotionListener(this);

}

public void paint(Graphics g)

{

if(k==1)

{

g.setColor(Color.red);

g.fillOval(xPos-5,yPos-5,10,10);

}

if(k==2)

{

super.update(g);

}

if(k==3)

{

g.setColor(Color.white);

g.fillOval(xPos-5,yPos-5,10,10);

}

}

public void actionPerformed(ActionEvent e){

if (e.getSource()==btnDraw)

k=1;

if(e.getSource()==btnClean){

k=2;

repaint();

}

if(e.getSource()==btnErase)

k=3;

}

public void mouseClicked(MouseEvent e)

{

}

public void mousePressed(MouseEvent e)

{

showStatus("鼠标键按下");

}

public void mouseReleased(MouseEvent e)

{

showStatus("鼠标键释放");

}

public void mouseEntered(MouseEvent e)

{

showStatus("鼠标进入");

}

public void mouseExited(MouseEvent e)

{

showStatus("鼠标移出");

}

public void mouseDragged(MouseEvent e)

{

xPos=e.getX();

yPos=e.getY();

repaint();

}

public void mouseMoved(MouseEvent e)

{

showStatus("鼠标移动");

}

public void update(Graphics g){

paint(g);

}

}

java绘图代码问题

我随手写了一个,你自己看看,注释我就不写了

import java.awt.Color;

import java.awt.Graphics;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class TestDraw implements ActionListener {

private JButton b1,b2,b3;

JFrame frame;

MyPanel panel;

public void init() {

frame = new JFrame();

frame.setBounds(100, 100, 400, 300);

frame.setTitle("画");

frame.setLayout(new GridLayout(2, 1));

JPanel p1 = new JPanel();

b1 = new JButton("直线");

b2 = new JButton("矩形");

b3 = new JButton("椭圆");

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

p1.add(b1);

p1.add(b2);

p1.add(b3);

panel = new MyPanel();

frame.add(p1);

frame.add(panel);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent e) {

if(e.getSource() == b1) {

panel.setFlag(0);

panel.repaint();

}else if(e.getSource() == b2) {

panel.setFlag(1);

panel.repaint();

}else if(e.getSource() == b3) {

panel.setFlag(2);

panel.repaint();

}

}

public static void main(String[] args) {

new TestDraw().init();

}

class MyPanel extends JPanel {

int flag = -1;

public MyPanel() {

this.setSize(400, 400);

this.setBackground(Color.white);

this.setVisible(true);

}

//画直线

public void drawL(Graphics g) {

g.drawLine(100, 20, 200, 20);

}

//画矩形

public void drawR(Graphics g) {

g.drawRect(100, 20, 200, 100);

}

//画椭圆

public void drawO(Graphics g) {

g.drawOval(100, 20, 200, 100);

}

@Override

public void paint(Graphics g) {

super.paint(g);

if(flag == 0) {

drawL(g);

}else if(flag == 1) {

drawR(g);

}else if(flag == 2) {

drawO(g);

}

}

public int getFlag() {

return flag;

}

public void setFlag(int flag) {

this.flag = flag;

}

}

}


当前题目:手机上绘图的java代码,手机上绘图的java代码怎么用
URL网址:http://hbruida.cn/article/hdcsso.html