Un programa mínimo que permite usar varias cosas de java. Lo hice para estudiar un parcial que me toman ésta tarde.
public class minicad{
public static void main(String args[]){
new form();
}
}import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
public class form extends JFrame implements ActionListener{
private JLabel label;
private DrawingArea Panel;
public form(){
super("MiniCAD");
setDefaultCloseOperation(EXIT_ON_CLOSE);
label = new JLabel("Programa simplista de graficación vectorial en java");
getContentPane().add(label, BorderLayout.NORTH);
Panel = new DrawingArea();
Panel.setBackground(Color.BLACK);
getContentPane().add(Panel, BorderLayout.CENTER);
JPanel Panel2 = new JPanel();
getContentPane().add(Panel2, BorderLayout.SOUTH);
Panel2.setLayout(new FlowLayout());
JButton Button = new JButton("Elegir archivo");
Panel2.add(Button);
Button.addActionListener(this);
setSize(500, 500);
show();
}
public void actionPerformed(ActionEvent e)
{
FileDialog fd = new FileDialog(this, "Elija el archivo");
fd.show();
File f = new File(fd.getDirectory(), fd.getFile());
label.setText("Procesando: " + f.getAbsolutePath());
try{
BufferedReader br = new BufferedReader(new FileReader(f));
String s;
Panel.ordenes.clear();
while((s = br.readLine())!= null) Panel.ordenes.add(s);
br.close();
}catch(java.io.IOException ioex){}
}
}
class DrawingArea extends JPanel {
Color drawColor;
public ArrayList ordenes;
public DrawingArea() {
drawColor = Color.yellow;
ordenes = new ArrayList();
}
private String getParam(StringBuffer s){
String r = new String();
int p = s.indexOf(" ");
r = s.substring(0, p);
s = s.delete(0, p+1);
return r;
}
public void paintComponent(Graphics g){
super.paintComponent(g);
for(int i = 0; i < ordenes.size(); i++){
String orden[] = (""+ordenes.get(i)).split(" ");
Color co;
if(orden[1].equals("red")) co = Color.RED;
else if(orden[1].equals("blue")) co = Color.BLUE;
else if(orden[1].equals("yellow")) co = Color.YELLOW;
else co = Color.WHITE;
g.setColor(co);
int a,b,c,d;
a = (new Integer(orden[2]).intValue());
b = (new Integer(orden[3]).intValue());
c = (new Integer(orden[4]).intValue());
d = (new Integer(orden[5]).intValue());
if(orden[0].equals("line")){
g.drawLine(a, b, c, d);
}else if(orden[0].equals("circle")){
g.drawOval(a, b, c, d);
}else if(orden[0].equals("rect")){
g.drawRect(a, b, c, d);
}
}
}
public void setMyColor(Color x){
drawColor = x;
repaint();
}
}
El archivo de ordenes:
line red 0 0 100 150
line red 100 150 200 250
circle blue 200 250 300 300
rect yellow 100 150 200 250
rect verde 10 10 134 132
circle white 0 0 140 300
circle white 50 50 300 200
line blue 120 120 150 150
line red 150 150 120 150
line yellow 120 150 120 120
Y un screenshot:

No tiene validación ni nada profesional, es solo para aprender rápido algunas cosas de java.
Saludos!