Nao vou enrolar pq eh mto código
Basicamente uma classe chama a outra que chama a que desenha as paradinhas
um exemplo de cada, ta bom assim?
import java.awt.event.*;
public class ExitListener extends WindowAdapter{
public void windowClosing(WindowEvent event){
System.exit(0);
}
}
-------------------------
import java.awt.*;
import javax.swing.*;
public class WindowUtilities {
public static void setNativeLookAndFeel(){
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch (Exception e) {
System.out.println("Deu erro:" + e);
}
}
public static JFrame openInFrame(Container container, int width, int height, String title, Color bgColor){
JFrame frame = new JFrame(title);
frame.setBackground(bgColor);
container.setBackground(bgColor);
frame.setSize(width, height);
frame.setContentPane(container);
frame.addWindowListener(new ExitListener());
frame.setVisible(true);
return(frame);
}
public static JFrame openInFrame(Container container, int width, int height){
return (openInFrame(container, width, height, container.getClass().getName(), Color.white ));
}
}
-----------------------------
import javax.swing.JPanel;
import java.awt.*;
import java.awt.geom.*;
public class Java2d extends JPanel {
private static final long serialVersionUID = -4849154246864000661L;
// espçamento entre os pontos
final static float dash1[] = {10.0f};
final static float dash2[] = {1.0f};
final static float dash3[] = {5.0f};
//tipo dos pontos
final static BasicStroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
final static BasicStroke dashed2 = new BasicStroke(5.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, dash2, 0.0f);
final static BasicStroke dashed3 = new BasicStroke(10.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2.0f, dash3, 0.0f);
final static BasicStroke dashed4 = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 2.0f, dash1, 0.0f);
final static BasicStroke dashed5 = new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 2.0f, dash2, 0.0f);
final static BasicStroke dashed6 = new BasicStroke(7.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 2.0f, dash3, 0.0f);
final static BasicStroke dashed7 = new BasicStroke(10.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 2.0f, dash1, 0.0f);
//desenhando um circunferencias
private final Ellipse2D.Double circle = new Ellipse2D.Double(5, 5, 150, 150);
private final Ellipse2D.Double circle2 = new Ellipse2D.Double(5, 220, 50, 150);
private final Ellipse2D.Double circle3 = new Ellipse2D.Double(5,165 , 150, 50);
private final Ellipse2D.Double circle4 = new Ellipse2D.Double(5, 400, 150, 150);
//desenhando quadráticos
private final Rectangle2D.Double square = new Rectangle2D.Double(200, 5,150, 150);
private final Rectangle2D.Double square2 = new Rectangle2D.Double(200, 200,50, 150);
private final Rectangle2D.Double square3 = new Rectangle2D.Double(200, 400,150, 50);
//desenhando linhas
private final Line2D.Double line = new Line2D.Double(450, 15 , 400, 65);
private final Line2D.Double line2 = new Line2D.Double(400, 100, 450, 150);
private final Line2D.Double line3 = new Line2D.Double(400, 200, 400, 350);
private final Line2D.Double line4 = new Line2D.Double(400, 400, 550, 400);
//mostrar na tela xD
public void paint(final Graphics g){
clear(g);
final Graphics2D g2d = (Graphics2D)g;
// seta o tipo da linha
g2d.setStroke(dashed);
//seta o desenho
g2d.draw(circle);
g2d.setStroke(dashed2);
g2d.draw(circle2);
g2d.setStroke(dashed3);
g2d.draw(circle3);
g2d.fill(circle4);
g2d.setStroke(dashed);
g2d.draw(square);
g2d.setStroke(dashed2);
g2d.draw(square2);
g2d.setStroke(dashed3);
g2d.draw(square3);
g2d.fill(square3);
g2d.setStroke(dashed4);
g2d.draw(line);
g2d.setStroke(dashed5);
g2d.draw(line2);
g2d.setStroke(dashed6);
g2d.draw(line3);
g2d.setStroke(dashed7);
g2d.draw(line4);
/*fill - para desenhos só com contorno
draw - preenche tudo
*/
}
protected void clear(final Graphics g){
super.paint(g);
}
public static void main(final String[] args){
WindowUtilities.openInFrame(new Java2d(), 580, 700);
}
}
Nenhum comentário:
Postar um comentário