欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java圖形編輯系統(tǒng)代碼,Java圖形界面編程

用JAVA編寫一個圖形應(yīng)用程序,可以是一個簡單的文本編輯器、計算器等等。 求完整代碼

//百度文庫找的,可費了我的財富值了,你可要把分給我呀。

成都創(chuàng)新互聯(lián)服務(wù)項目包括成安網(wǎng)站建設(shè)、成安網(wǎng)站制作、成安網(wǎng)頁制作以及成安網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,成安網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到成安省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

package lee;

/*文件名:Calculator.java

*說明:簡易科學(xué)計算器

*/

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Calculator extends Frame implements ActionListener, WindowListener

{

private Container container;

private GridBagLayout layout;

private GridBagConstraints constraints;

private JTextField displayField; //計算結(jié)果顯示區(qū)

private String lastCommand; //保存+,-,*,/,=命令0

private double result; //保存計算結(jié)果

private boolean start; //判斷是否為數(shù)字的開始

private JMenuBar menubar;

private JMenuItem m_exit,m2_ejz,m2_bjz;

private Dialog dialog;

private Label label_dialog;

private JButton button_sqrt,button_plusminus,button_CE,button_cancel,button_1,button_2,

button_3,button_4,button_5,button_6,button_7,button_8,button_9,button_0,

button_plus,button_minus,button_multiply,button_divide,button_point,

button_equal,button_log,button_tan,button_cos,button_sin,button_exp;

public Calculator() //構(gòu)造方法設(shè)置布局、為按鈕注冊事件監(jiān)聽器

{

super("Calculator");

this.setLocation(240,200);

this.setSize(350,300);

this.setResizable(true);

this.setLayout(new GridLayout(7,1));

this.addmyMenu(); //調(diào)用成員方法添加菜單

displayField=new JTextField(30);

this.add(displayField);

displayField.setEditable(true);

start=true;

result=0;

lastCommand = "=";

JPanel panel0=new JPanel();

panel0.setLayout(new GridLayout(1,4,4,4));

JPanel panel1=new JPanel();

panel1.setLayout(new GridLayout(1,5,4,4));

this.add(panel1);

button_sqrt=new JButton("sqrt");

button_plusminus=new JButton("+/-");

button_exp=new JButton("exp");

button_CE=new JButton("退格");

button_cancel=new JButton("C");

JPanel panel2=new JPanel();

panel2.setLayout(new GridLayout(1,5,4,4));

this.add(panel2);

button_7=new JButton("7");

button_8=new JButton("8");

button_9=new JButton("9");

button_log=new JButton("log");

button_divide=new JButton("/");

JPanel panel3=new JPanel();

panel3.setLayout(new GridLayout(1,5,4,4));

this.add(panel3);

button_4=new JButton("4");

button_5=new JButton("5");

button_6=new JButton("6");

button_tan=new JButton("tan");

button_multiply=new JButton("*");

JPanel panel4=new JPanel();

panel4.setLayout(new GridLayout(1,5,4,4));

this.add(panel4);

button_1=new JButton("1");

button_2=new JButton("2");

button_3=new JButton("3");

button_cos=new JButton("cos");

button_minus=new JButton("-");

JPanel panel5=new JPanel();

panel5.setLayout(new GridLayout(1,5,4,4));

this.add(panel5);

button_0=new JButton("0");

button_point=new JButton(".");

button_equal=new JButton("=");

button_sin=new JButton("sin");

button_plus=new JButton("+");

panel1.add(button_sqrt);

panel1.add(button_plusminus);

panel1.add(button_exp);

panel1.add(button_CE);

panel1.add(button_cancel);

panel2.add(button_7);

panel2.add(button_8);

panel2.add(button_9);

panel2.add(button_log);

panel2.add(button_divide);

panel3.add(button_4);

panel3.add(button_5);

panel3.add(button_6);

panel3.add(button_tan);

panel3.add(button_multiply);

panel4.add(button_1);

panel4.add(button_2);

panel4.add(button_3);

panel4.add(button_cos);

panel4.add(button_minus);

panel5.add(button_0);

panel5.add(button_point);

panel5.add(button_equal);

panel5.add(button_sin);

panel5.add(button_plus);

button_sqrt.addActionListener(this);

button_plusminus.addActionListener(this);

button_exp.addActionListener(this);

button_CE.addActionListener(this);

button_cancel.addActionListener(this);

button_7.addActionListener(this);

button_8.addActionListener(this);

button_9.addActionListener(this);

button_log.addActionListener(this);

button_divide.addActionListener(this);

button_4.addActionListener(this);

button_5.addActionListener(this);

button_6.addActionListener(this);

button_tan.addActionListener(this);

button_multiply.addActionListener(this);

button_1.addActionListener(this);

button_2.addActionListener(this);

button_3.addActionListener(this);

button_cos.addActionListener(this);

button_minus.addActionListener(this);

button_0.addActionListener(this);

button_point.addActionListener(this);

button_equal.addActionListener(this);

button_sin.addActionListener(this);

button_plus.addActionListener(this);

this.addWindowListener(new WinClose()); //注冊窗口監(jiān)聽器

this.setVisible(true);

}

private void addmyMenu() //菜單的添加

{

JMenuBar menubar=new JMenuBar();

this.add(menubar);

JMenu m1=new JMenu("選項");

JMenu m2=new JMenu("進制轉(zhuǎn)換");

JMenuItem m1_exit=new JMenuItem("退出");

m1_exit.addActionListener(this);

JMenuItem m2_ejz=new JMenuItem("二進制");

m2_ejz.addActionListener(this);

JMenuItem m2_bjz=new JMenuItem("八進制");

m2_bjz.addActionListener(this);

JMenu m3 = new JMenu(" 幫助");

JMenuItem m3_Help = new JMenuItem("用法");

m3_Help.addActionListener(this);

dialog = new Dialog(this,"提示",true); //模式窗口

dialog.setSize(240,80);

label_dialog = new Label("",Label.CENTER); //標(biāo)簽的字符串為空,居中對齊

dialog.add(label_dialog);

dialog.addWindowListener(this); //為對話框注冊窗口事件監(jiān)聽器

m1.add(m1_exit);

menubar.add(m1);

m2.add(m2_ejz);

m2.add(m2_bjz);

menubar.add(m2);

m3.add(m3_Help);

menubar.add(m3); }

public void actionPerformed(ActionEvent e) //按鈕的單擊事件處理方法

{

if(e.getSource().equals(button_1)||e.getSource().equals(button_2)||

e.getSource().equals(button_3)||e.getSource().equals(button_4)||

e.getSource().equals(button_5)|| e.getSource().equals(button_6)||

e.getSource().equals(button_7)|| e.getSource().equals(button_8)||

e.getSource().equals(button_9) ||e.getSource().equals(button_0)||

e.getSource().equals(button_point)||e.getSource().equals(button_plusminus)||

e.getSource().equals(button_cancel)||e.getSource().equals(button_CE))

{ //非運算符的處理方法

String input=e.getActionCommand();

if (start)

{

displayField.setText("");

start=false;

if(input.equals("+/-"))

displayField.setText(displayField.getText()+"-");

}

if(!input.equals("+/-"))

{

String str=displayField.getText();

if(input.equals("退格")) //退格鍵的實現(xiàn)方法

{

if(str.length()0)

displayField.setText(str.substring(0,str.length()-1));

}

else if(input.equals("C")) //清零鍵的實現(xiàn)方法

{

displayField.setText("0");

start=true;

}

else

displayField.setText(displayField.getText()+input);

}

}

else if (e.getActionCommand()=="二進制") //二進制的轉(zhuǎn)換

{

int n=Integer.parseInt(displayField.getText());

displayField.setText(Integer.toBinaryString(n));

}

else if (e.getActionCommand()=="八進制") //八進制的轉(zhuǎn)換

{

int n=Integer.parseInt(displayField.getText());

displayField.setText(Integer.toOctalString(n));

}

else if (e.getActionCommand()=="退出") //選項中退出的處理方法

{

System.exit(0);

}

else if (e.getActionCommand()=="用法") //按下'幫助'菜單欄中用法的處理方法

{

label_dialog.setText("sqrt,exp等鍵是先輸運算符再輸數(shù)字\n");

dialog.setLocation(400,250);

dialog.setVisible(true);

}

else //各運算符的識別

{

String command=e.getActionCommand();

if(start)

{

lastCommand=command;

}

else

{

calculate(Double.parseDouble(displayField.getText()));

lastCommand=command;

start=true;

}

}

}

public void calculate(double x) //各運算符的具體運算方法

{

double d=0;

if (lastCommand.equals("+"))

result+= x;

else if (lastCommand.equals("-"))

result-=x;

else if (lastCommand.equals("*"))

result*=x;

else if (lastCommand.equals("/"))

result/=x;

else if (lastCommand.equals("="))

result=x;

else if (lastCommand.equals("sqrt"))

{

d=Math.sqrt(x);

result=d;

}

else if (lastCommand.equals("exp"))

{

d=Math.exp(x);

result=d;

}

else if (lastCommand.equals("log"))

{

d=Math.log(x);

result=d;

}

else if (lastCommand.equals("tan"))

{

d=Math.tan(x);

result=d;

}

else if (lastCommand.equals("cos"))

{

d=Math.cos(x);

result=d;

}

else if (lastCommand.equals("sin"))

{

d=Math.sin(x);

result=d;

}

displayField.setText(""+ result);

}

public void windowClosing(WindowEvent e)

{

if(e.getSource()==dialog)

dialog.setVisible(false); //隱藏對話框

else

System.exit(0);

}

public void windowOpened(WindowEvent e) { }

public void windowActivated(WindowEvent e) { }

public void windowDeactivated(WindowEvent e) { }

public void windowClosed(WindowEvent e) { }

public void windowIconified(WindowEvent e) { }

public void windowDeiconified(WindowEvent e) { }

public static void main(String args[])

{

Calculator calculator=new Calculator();

}

}

class WinClose implements WindowListener

{

public void windowClosing(WindowEvent e) //單擊窗口關(guān)閉按鈕時觸發(fā)并執(zhí)行實現(xiàn)窗口監(jiān)聽器接口中的方法

{

System.exit(0); //結(jié)束程序運行

}

public void windowOpened(WindowEvent e){}

public void windowActivated(WindowEvent e){}

public void windowDeactivated(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

}

Java編寫圖形用戶界面程序

運行如圖

參考代碼如下

import?java.awt.*;

import?java.awt.event.*;

import?javax.swing.*;

public?class?RegDemo?extends?JFrame?implements?ActionListener{

JTextField?jtf;

JPasswordField?jpf;

public?RegDemo()?{

//組件的創(chuàng)建,?和布局安排

JPanel?jpc?=?new?JPanel();//默認流式布局

JPanel?jp1?=?new?JPanel(new?GridLayout(2,?2,5,10));//網(wǎng)格布局

jp1.setBorder(BorderFactory.createTitledBorder("用戶注冊"));

JLabel?jl1?=?new?JLabel("用戶名:");

jtf?=?new?JTextField(10);

JLabel?jl2?=?new?JLabel("密碼:");

jpf?=?new?JPasswordField(10);

jpf.setEchoChar('*');//用*號來隱藏密碼的顯示

jp1.add(jl1);jp1.add(jtf);

jp1.add(jl2);jp1.add(jpf);

jpc.add(jp1);

add(jpc);

JButton?jb1?=?new?JButton("提交");

jb1.addActionListener(this);

jb1.setActionCommand("yes");

JButton?jb2?=?new?JButton("取消");

jb2.addActionListener(this);

jb2.setActionCommand("no");

JPanel?jp2?=?new?JPanel();

jp2.add(jb1);jp2.add(jb2);

add(jp2,BorderLayout.SOUTH);

setTitle("用戶注冊界面");

setSize(280,?280);

setLocationRelativeTo(null);//窗口居中

setDefaultCloseOperation(EXIT_ON_CLOSE);//

setVisible(true);

}

public?static?void?main(String[]?args)?{

new?RegDemo();

}

@Override

public?void?actionPerformed(ActionEvent?e)?{

if(e.getActionCommand().equals("yes")){

String?name??=?jtf.getText().trim();

String?pwd?=?new?String(jpf.getPassword());

if(name.equals("")||pwd.equals("")){

JOptionPane.showMessageDialog(this,?"你還沒有輸入用戶名或者密碼");

}else{

JOptionPane.showMessageDialog(this,?"注冊成功!用戶名"+name+",密碼"+pwd);

}

}else{

jtf.setText("");

jpf.setText("");

}

}

}

java圖形界面代碼解惑

一般來說.比較常使用的是?JTextArea文本框的無參數(shù)構(gòu)造器進行構(gòu)造

然后可以使用setText("文字")來設(shè)置文本,或者getText()方法來獲得文本

JTextArea?jta?=?new?JTextArea();

jta.setText("你好啊");

String?txt?=?jta.getText();

具體例子

import?java.awt.*;

import?java.awt.event.*;

import?java.io.*;

import?javax.swing.*;

public?class?ReadBook?extends?JFrame{

JTextArea?jta;

JTextField?jtf;

JButton?jb;

public?ReadBook(){

jta?=?new?JTextArea();

jtf?=?new?JTextField(30);

jtf.setText("文件路徑如c:\\ab.txt");

jb?=?new?JButton("顯示文字");

JPanel?jp?=?new?JPanel();

jp.add(jtf);

jp.add(jb);

add(jta);

add(jp,BorderLayout.SOUTH);

setBounds(500,?100,?500,?380);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

jb.addActionListener(new?ActionListener()?{

@Override

public?void?actionPerformed(ActionEvent?e)?{

String?path?=?jtf.getText();

File?f=?new?File(path);

if(f.exists()!f.isDirectory()){//存在該文件且不是文件夾

try?{

StringBuilder?sb?=?new?StringBuilder();

BufferedReader?br?=?new?BufferedReader(new?FileReader(f));

String?temp;

while((temp=br.readLine())!=null){

sb.append(temp+"\n");

}

br.close();

jta.setText(sb.toString());//setText方法可以給jta添加文字

}?catch?(Exception?e1)?{

e1.printStackTrace();

}

}else{

jtf.setText("路徑錯誤.重新填寫");

}

}

});

}

public?static?void?main(String[]?args)?{

new?ReadBook();

}

}

效果

求一個簡單的java代碼:(圖形界面)

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JDialog;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class vv extends JDialog {

private static final long serialVersionUID = 1L;

private JLabel l_Id = new JLabel("登陸賬戶", JLabel.CENTER);

private JLabel l_pw = new JLabel("登陸密碼", JLabel.CENTER);

private JTextField t_Id = new JTextField(10);

private JPasswordField t_pw = new JPasswordField(10);

private JButton btnLogin;

private JButton btnClose;

public vv() {

super();

setResizable(false);

getContentPane().setBackground(new Color(225, 225, 225));

getContentPane().setLayout(null);

initialize();

}

protected void initialize() {

setTitle("系統(tǒng)登錄");

l_Id.setBounds(48, 43, 53, 25);

t_Id.setBounds(110, 43, 150, 25);

l_pw.setBounds(48, 93, 53, 25);

t_pw.setBounds(110, 93, 150, 25);

getContentPane().add(l_Id);

getContentPane().add(l_pw);

getContentPane().add(t_Id);

getContentPane().add(t_pw);

btnLogin = new JButton();

btnLogin.setText("登 錄");

btnLogin.setBounds(70, 142, 85, 28);

btnLogin.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

addBtnLoginActionListener();

}

});

getContentPane().add(btnLogin);

btnClose = new JButton();

btnClose.setText("關(guān) 閉");

btnClose.setBounds(175, 142, 85, 28);

btnClose.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

dispose();

System.exit(-1);

}

});

getContentPane().add(btnClose);

}

private void addBtnLoginActionListener() {

String user = t_Id.getText();

String password = new String(t_pw.getPassword());

if (user.equals("")) {

JOptionPane.showMessageDialog(this, "帳號不可為空", "Caution",

JOptionPane.WARNING_MESSAGE);

return;

}

if (password.equals("")) {

JOptionPane.showMessageDialog(this, "密碼不可為空", "Caution",

JOptionPane.WARNING_MESSAGE);

return;

}

String sql = "select * FROM login WHERE id = '" + user + "' and pw = '"

+ password + "'";

boolean success = false;

// TODO:數(shù)據(jù)校驗 success = executeQuery(sql);

if (success) {

// TODO: 如果數(shù)據(jù)校驗成功 顯示主界面 并關(guān)閉登錄界面

JOptionPane.showMessageDialog(this, "成功登錄", "提示",

JOptionPane.INFORMATION_MESSAGE);

this.dispose();

} else {

JOptionPane.showMessageDialog(this, "帳號或密碼錯誤!", "警告",

JOptionPane.WARNING_MESSAGE);

t_pw.requestFocus(); // 密碼框選中

}

}

public Dimension getPreferredSize() {

return new Dimension(320, 170);

}

public void show() {

Toolkit tk = Toolkit.getDefaultToolkit();

Dimension screen = tk.getScreenSize();

Dimension d = getSize();

this.setLocation((screen.width - d.width) / 2,

(screen.height - d.height) / 2);

// 輸入密碼后回車相當(dāng)于點擊了登錄按鈕

getRootPane().setDefaultButton(btnLogin);

t_pw.requestFocus();

setDefaultCloseOperation(DISPOSE_ON_CLOSE);

setSize(300, 220);

super.show();

}

public static void main(String[] args) {

vv loginFrame = new vv();

loginFrame.setVisible(true);

}

}

希望對你有幫助

用JAVA實現(xiàn)的圖形編輯器

樓主給你一個我的,直接保存成pb.java編譯運行,就是你要的畫圖功能 ,可以參考一下

____________________________________________________________________

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import javax.swing.*;

import java.awt.geom.*;

import java.io.*;

class Point implements Serializable

{

int x,y;

Color col;

int tool;

int boarder;

Point(int x, int y, Color col, int tool, int boarder)

{

this.x = x;

this.y = y;

this.col = col;

this.tool = tool;

this.boarder = boarder;

}

}

class paintboard extends Frame implements ActionListener,MouseMotionListener,MouseListener,ItemListener

{

int x = -1, y = -1;

int con = 1;//畫筆大小

int Econ = 5;//橡皮大小

int toolFlag = 0;//toolFlag:工具標(biāo)記

//toolFlag工具對應(yīng)表:

//(0--畫筆);(1--橡皮);(2--清除);

//(3--直線);(4--圓);(5--矩形);

Color c = new Color(0,0,0); //畫筆顏色

BasicStroke size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);//畫筆粗細

Point cutflag = new Point(-1, -1, c, 6, con);//截斷標(biāo)志

Vector paintInfo = null;//點信息向量組

int n = 1;

FileInputStream picIn = null;

FileOutputStream picOut = null;

ObjectInputStream VIn = null;

ObjectOutputStream VOut = null;

// *工具面板--畫筆,直線,圓,矩形,多邊形,橡皮,清除*/

Panel toolPanel;

Button eraser, drLine,drCircle,drRect;

Button clear ,pen;

Choice ColChoice,SizeChoice,EraserChoice;

Button colchooser;

Label 顏色,大小B,大小E;

//保存功能

Button openPic,savePic;

FileDialog openPicture,savePicture;

paintboard(String s)

{

super(s);

addMouseMotionListener(this);

addMouseListener(this);

paintInfo = new Vector();

/*各工具按鈕及選擇項*/

//顏色選擇

ColChoice = new Choice();

ColChoice.add("black");

ColChoice.add("red");

ColChoice.add("blue");

ColChoice.add("green");

ColChoice.addItemListener(this);

//畫筆大小選擇

SizeChoice = new Choice();

SizeChoice.add("1");

SizeChoice.add("3");

SizeChoice.add("5");

SizeChoice.add("7");

SizeChoice.add("9");

SizeChoice.addItemListener(this);

//橡皮大小選擇

EraserChoice = new Choice();

EraserChoice.add("5");

EraserChoice.add("9");

EraserChoice.add("13");

EraserChoice.add("17");

EraserChoice.addItemListener(this);

////////////////////////////////////////////////////

toolPanel = new Panel();

clear = new Button("清除");

eraser = new Button("橡皮");

pen = new Button("畫筆");

drLine = new Button("畫直線");

drCircle = new Button("畫圓形");

drRect = new Button("畫矩形");

openPic = new Button("打開圖畫");

savePic = new Button("保存圖畫");

colchooser = new Button("顯示調(diào)色板");

//各組件事件監(jiān)聽

clear.addActionListener(this);

eraser.addActionListener(this);

pen.addActionListener(this);

drLine.addActionListener(this);

drCircle.addActionListener(this);

drRect.addActionListener(this);

openPic.addActionListener(this);

savePic.addActionListener(this);

colchooser.addActionListener(this);

顏色 = new Label("畫筆顏色",Label.CENTER);

大小B = new Label("畫筆大小",Label.CENTER);

大小E = new Label("橡皮大小",Label.CENTER);

//面板添加組件

toolPanel.add(openPic);

toolPanel.add(savePic);

toolPanel.add(pen);

toolPanel.add(drLine);

toolPanel.add(drCircle);

toolPanel.add(drRect);

toolPanel.add(顏色); toolPanel.add(ColChoice);

toolPanel.add(大小B); toolPanel.add(SizeChoice);

toolPanel.add(colchooser);

toolPanel.add(eraser);

toolPanel.add(大小E); toolPanel.add(EraserChoice);

toolPanel.add(clear);

//工具面板到APPLET面板

add(toolPanel,BorderLayout.NORTH);

setBounds(60,60,900,600); setVisible(true);

validate();

//dialog for save and load

openPicture = new FileDialog(this,"打開圖畫",FileDialog.LOAD);

openPicture.setVisible(false);

savePicture = new FileDialog(this,"保存圖畫",FileDialog.SAVE);

savePicture.setVisible(false);

openPicture.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{ openPicture.setVisible(false); }

});

savePicture.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{ savePicture.setVisible(false); }

});

addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{ System.exit(0);}

});

}

public void paint(Graphics g)

{

Graphics2D g2d = (Graphics2D)g;

Point p1,p2;

n = paintInfo.size();

if(toolFlag==2)

g.clearRect(0,0,getSize().width,getSize().height);//清除

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

p1 = (Point)paintInfo.elementAt(i);

p2 = (Point)paintInfo.elementAt(i+1);

size = new BasicStroke(p1.boarder,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

g2d.setColor(p1.col);

g2d.setStroke(size);

if(p1.tool==p2.tool)

{

switch(p1.tool)

{

case 0://畫筆

Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);

g2d.draw(line1);

break;

case 1://橡皮

g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder);

break;

case 3://畫直線

Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);

g2d.draw(line2);

break;

case 4://畫圓

Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x-p1.x) , Math.abs(p2.y-p1.y));

g2d.draw(ellipse);

break;

case 5://畫矩形

Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x-p1.x) , Math.abs(p2.y-p1.y));

g2d.draw(rect);

break;

case 6://截斷,跳過

i=i+1;

break;

default :

}//end switch

}//end if

}//end for

}

public void itemStateChanged(ItemEvent e)

{

if(e.getSource()==ColChoice)//預(yù)選顏色

{

String name = ColChoice.getSelectedItem();

if(name=="black")

{c = new Color(0,0,0); }

else if(name=="red")

{c = new Color(255,0,0);}

else if(name=="green")

{c = new Color(0,255,0);}

else if(name=="blue")

{c = new Color(0,0,255);}

}

else if(e.getSource()==SizeChoice)//畫筆大小

{

String selected = SizeChoice.getSelectedItem();

if(selected=="1")

{

con = 1;

size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

}

else if(selected=="3")

{

con = 3;

size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

}

else if(selected=="5")

{con = 5;

size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

}

else if(selected=="7")

{con = 7;

size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

}

else if(selected=="9")

{con = 9;

size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);

}

}

else if(e.getSource()==EraserChoice)//橡皮大小

{

String Esize = EraserChoice.getSelectedItem();

if(Esize=="5")

{ Econ = 5*2; }

else if(Esize=="9")

{ Econ = 9*2; }

else if(Esize=="13")

{ Econ = 13*2; }

else if(Esize=="17")

{ Econ = 17*3; }

}

}

public void mouseDragged(MouseEvent e)

{

Point p1 ;

switch(toolFlag){

case 0://畫筆

x = (int)e.getX();

y = (int)e.getY();

p1 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p1);

repaint();

break;

case 1://橡皮

x = (int)e.getX();

y = (int)e.getY();

p1 = new Point(x, y, null, toolFlag, Econ);

paintInfo.addElement(p1);

repaint();

break;

default :

}

}

public void mouseMoved(MouseEvent e) {}

public void update(Graphics g)

{

paint(g);

}

public void mousePressed(MouseEvent e)

{

Point p2;

switch(toolFlag){

case 3://直線

x = (int)e.getX();

y = (int)e.getY();

p2 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p2);

break;

case 4: //圓

x = (int)e.getX();

y = (int)e.getY();

p2 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p2);

break;

case 5: //矩形

x = (int)e.getX();

y = (int)e.getY();

p2 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p2);

break;

default :

}

}

public void mouseReleased(MouseEvent e)

{

Point p3;

switch(toolFlag){

case 0://畫筆

paintInfo.addElement(cutflag);

break;

case 1: //eraser

paintInfo.addElement(cutflag);

break;

case 3://直線

x = (int)e.getX();

y = (int)e.getY();

p3 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p3);

paintInfo.addElement(cutflag);

repaint();

break;

case 4: //圓

x = (int)e.getX();

y = (int)e.getY();

p3 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p3);

paintInfo.addElement(cutflag);

repaint();

break;

case 5: //矩形

x = (int)e.getX();

y = (int)e.getY();

p3 = new Point(x, y, c, toolFlag, con);

paintInfo.addElement(p3);

paintInfo.addElement(cutflag);

repaint();

break;

default:

}

}

public void mouseEntered(MouseEvent e){}

public void mouseExited(MouseEvent e){}

public void mouseClicked(MouseEvent e){}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==pen)//畫筆

{toolFlag = 0;}

if(e.getSource()==eraser)//橡皮

{toolFlag = 1;}

if(e.getSource()==clear)//清除

{

toolFlag = 2;

paintInfo.removeAllElements();

repaint();

}

if(e.getSource()==drLine)//畫線

{toolFlag = 3;}

if(e.getSource()==drCircle)//畫圓

{toolFlag = 4;}

if(e.getSource()==drRect)//畫矩形

{toolFlag = 5;}

if(e.getSource()==colchooser)//調(diào)色板

{

Color newColor = JColorChooser.showDialog(this,"調(diào)色板",c);

c = newColor;

}

if(e.getSource()==openPic)//打開圖畫

{

openPicture.setVisible(true);

if(openPicture.getFile()!=null)

{

int tempflag;

tempflag = toolFlag;

toolFlag = 2 ;

repaint();

try{

paintInfo.removeAllElements();

File filein = new File(openPicture.getDirectory(),openPicture.getFile());

picIn = new FileInputStream(filein);

VIn = new ObjectInputStream(picIn);

paintInfo = (Vector)VIn.readObject();

VIn.close();

repaint();

toolFlag = tempflag;

}

catch(ClassNotFoundException IOe2)

{

repaint();

toolFlag = tempflag;

System.out.println("can not read object");

}

catch(IOException IOe)

{

repaint();

toolFlag = tempflag;

System.out.println("can not read file");

}

}

}

if(e.getSource()==savePic)//保存圖畫

{

savePicture.setVisible(true);

try{

File fileout = new File(savePicture.getDirectory(),savePicture.getFile());

picOut = new FileOutputStream(fileout);

VOut = new ObjectOutputStream(picOut);

VOut.writeObject(paintInfo);

VOut.close();

}

catch(IOException IOe)

{

System.out.println("can not write object");

}

}

}

}//end paintboard

public class pb

{

public static void main(String args[])

{ new paintboard("畫圖程序"); }

}

分享題目:java圖形編輯系統(tǒng)代碼,Java圖形界面編程
網(wǎng)址分享:http://chinadenli.net/article35/dsgsgsi.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作App開發(fā)域名注冊網(wǎng)站營銷做網(wǎng)站靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司