[Java] How to make a Swing Paint and Drawing application ?

preview_player
Показать описание
Tutorial showing How to make a Swing Paint and Drawing application ?

Рекомендации по теме
Комментарии
Автор

I love you man, thanks A LOT FOR THIS!!!

allexj
Автор

sound must be there for better explanation...without sound its quite difficult to understand

tarangsinha
Автор

Is there a way to increase the size and soften up the edges? Like brushes or for pencil.

zZJoennZz
Автор

How do you function without line numbers?

milesdavidsmith
Автор

Hi :) how can i change the color on an Paint android application ? setColor change all of the colors, and i cant use setPaint and Graphics2D in android pls help me ! <3

tlion
Автор

How to draw square by dragging the mouse and releasing ??

saadirehman
Автор

Hey Sylvain, when i execute the code, a java app launches in my mac launchpad, but then disappears and the Java application does not launch, all code produces no errors. Any help?

carolynfyffe
Автор

/*
How to make this more efficient, and i need to draw to continuous line, but it is breaking
*/


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;

public class Paint2 extends JFrame implements MouseListener, MouseMotionListener, ActionListener{
int X, Y, co=0, c, x1, x2, y1, y2;
Button b1, b2, r, g, b, w, black, m, o, y, pink, cyan, clear, line;
Panel panel1;
Graphics gr;
boolean lflag=false, p=false, e=false;
Color[] colors ={Color.RED, Color.BLUE, Color.GREEN, Color.WHITE, Color.MAGENTA, Color.ORANGE, Color.pink, Color.CYAN, Color.BLACK, Color.YELLOW};
Paint2(){
super("Paint2");
setVisible(true);

setSize(700, 700);
setLayout(null);

panel1 = new Panel(new FlowLayout());
panel1.setBounds(0, 0, 80, 700);



addMouseListener(this);

b1 = new Button("paint");
b2 = new Button("erase");
clear = new Button("clear");
line = new Button("line");

r = new Button("red");
g = new Button("green");
b = new Button("blue");
m = new Button("magenta");
pink = new Button("pink");
y = new Button("yellow");
o = new Button("orange");
cyan= new Button("cyan");
black = new Button("black");

panel1.add(b1);
panel1.add(b2);
panel1.add(clear);
panel1.add(line);

b1.addActionListener(this);
b2.addActionListener(this);

r.addActionListener(this);
g.addActionListener(this);
b.addActionListener(this);
o.addActionListener(this);
m.addActionListener(this);
y.addActionListener(this);




add(panel1);
}
public void actionPerformed(ActionEvent ae){
= true; e =false;lflag = false; co =0;}
else = false; e =true;lflag = false; co =0;}
else {lflag=true;p=false;e=false; co =0;}
else
gr= getGraphics();
gr.setColor(colors[3]);
gr.fillRect(0, 0, 700, 700);
}
else
else
else
else
else
else
else
else
else
}


public void mouseClicked(MouseEvent e){
gr = getGraphics();
System.out.println("click");
if( lflag && co==0){
x1 = e.getX();
y1 = e.getY();
gr.setColor(colors[c]);
gr.fillOval(x1, y1, 5, 5);
co++;
}else if(lflag && co==1){
x2 = e.getX();
y2 = e.getY();
gr.setColor(colors[c]);
gr.fillOval(x2, y2, 5, 5);
gr.drawLine(x1, y1, x2, y2);
x1 = x2;
y1 = y2;
}
}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}

public void mouseMoved(MouseEvent e){}
public void mouseDragged(MouseEvent me){
X=me.getX();
Y=me.getY();
gr = getGraphics();
if(p==true){
gr.setColor(colors[c]);
gr.fillOval(X, Y, 6, 6);
}else if(e==true){
gr.setColor(colors[3]);
gr.fillOval(X, Y, 15, 15);
}
}
public static void main(String[] ag){
new Paint2();
}
}

purnamaheshimmandi