Tuesday, July 12, 2005

Nuestro Grafo!

import java.awt.Color;
import java.awt.Graphics;
import java.util.Map; // clase abstracta para el soporte de TreeMap
import java.util.TreeMap; // clase que permite hacer listas dinamicas y con valores diferentes
/*
* Grafos.java
*
* Created on 6 de julio de 2005, 04:47 PM
*/
/**
*
* @author voip
*/
public class Grafos extends javax.swing.JFrame {
private boolean add = false;
/** Creates new form Grafos */
public Grafos() {
initComponents();
this.repaint();
for( int y=0; y < this.MapMethod().size(); y++ )
{
jComboBox1.addItem( this.MapMethod().get(y) );
}
}
public void paint( Graphics g )
{
g.drawOval( 350, 30, 90, 30 ); //A
g.drawString( this.MapMethod().get(0).toString(), 370, 50 );
g.drawOval(220, 85, 90, 30 ); //A-1
// pos. X pos. Y ancho alto
g.drawString( this.MapMethod().get(1).toString(), 240, 105 );
g.drawOval( 470, 85, 90, 30 ); //A-2
g.drawString( this.MapMethod().get(2).toString(), 490, 105 );
g.drawOval(130, 140, 90, 30); //A-B-1
g.drawString( this.MapMethod().get(3).toString(), 150, 160 );
g.drawOval(300, 140, 90, 30 ); //A-B-2
g.drawString( this.MapMethod().get(4).toString(), 315, 160 );
g.drawOval( 395, 140, 90, 30 ); //A-B-3
g.drawString( this.MapMethod().get(5).toString(), 415, 160 );
g.drawOval( 550, 140, 90, 30 ); //A-B-4
g.drawString( this.MapMethod().get(6).toString(), 570, 160 );
g.drawLine( 310, 100, 390, 60);
g.drawLine( 405, 60, 470, 100);
// x1 y1 x2 y2
g.drawLine( 190, 140, 250, 115); // A-1 --> A-B-1
g.drawLine( 340, 140, 280, 115); // A-1 --> A-B-2
g.drawLine(450, 140, 510, 115); // A-2 --> A-B-3
g.drawLine( 600, 140, 520, 115); // A-2 --> A-B-4
if ( add )
{
if ( jComboBox1.getSelectedItem().toString().equals( this.MapMethod().get(6).toString() ) )
{
g.drawLine( 670, 200, 620, 170 );
g.drawOval( 640, 200, 90, 30 );
g.drawString( jTextField1.getText(), 650, 220 );
}
else if ( jComboBox1.getSelectedItem().toString().equals( this.MapMethod().get(5).toString() ) )
{
g.drawLine( 440, 200, 440, 170 );
g.drawOval( 395, 200, 90, 30 );
g.drawString( jTextField1.getText(), 410, 220 );
}
else if ( jComboBox1.getSelectedItem().toString().equals( this.MapMethod().get(4).toString() ) )
{
g.drawLine( 340, 200, 340, 170 );
g.drawOval( 295, 200, 90, 30 );
g.drawString( jTextField1.getText(), 310, 220 );
}
else if ( jComboBox1.getSelectedItem().toString().equals( this.MapMethod().get(3).toString() ) )
{
g.drawLine( 170, 200, 170, 170 );
g.drawOval( 125, 200, 90, 30 );
g.drawString( jTextField1.getText(), 150, 220 );
}
}
}
public void update( Graphics g )
{
g.setColor(Color.black);
this.paint(g);
}
public Map MapMethod()
{
Map names = new TreeMap();
names.put(0,"Luis Soto");
names.put(1,"Maria Soto");
names.put(2,"Gladys Soto");
names.put(3,"Rafael Soto");
names.put(4,"Ernesto Soto");
names.put(5,"Jose Soto");
names.put(6,"Karen Soto");
return names;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jComboBox1 = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.GridLayout());
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jPanel1.add(jTextField1);
jPanel1.add(jComboBox1);
getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-811)/2, (screenSize.height-551)/2, 811, 551);
}
//
//GEN-END:initComponents
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
// TODO add your handling code here:
add = true;
this.repaint();
}//GEN-LAST:event_jTextField1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
Grafos grafo = new Grafos();
grafo.setVisible(true);
/*Grafos g = new Grafos();
g.repaint();
g.setVisible(true);
*/
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox jComboBox1;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}

0 Comments:

Post a Comment

<< Home