arahman22

GraphDrawViewer.java

Feb 21st, 2012
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. import javax.swing.JButton;
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8. import javax.swing.JTextField;
  9.  
  10.  
  11. public class GraphDrawViewer {
  12.  
  13.     /**
  14.      * @param args
  15.      */
  16.     public static void main(String[] args) {
  17.         final GraphDrawComponent graphcomp = new GraphDrawComponent();
  18.         // TODO Auto-generated method stub
  19.         JFrame frame = new JFrame();
  20.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  21.        
  22.         JPanel panel = new JPanel();
  23.        
  24.        
  25.         frame.setSize(720, 480);
  26.         frame.setTitle("Graph Viewer");
  27.        
  28.         JButton Rectangle = new JButton ("Rectangle");
  29.         JButton Ellipse = new JButton ("Ellipse");
  30.         JButton Edge = new JButton ("Edge");
  31.         JButton Label = new JButton ("Label");
  32.         final JTextField Text = new JTextField(20);
  33.         panel.add (Rectangle);
  34.         panel.add (Ellipse);
  35.         panel.add (Edge);
  36.         panel.add (Label);
  37.         panel.add (Text);
  38.        
  39.         class RectangleDrawer implements ActionListener
  40.         {
  41.  
  42.             @Override
  43.             public void actionPerformed(ActionEvent e)
  44.             {
  45.                 graphcomp.addRectangle();
  46.             }      
  47.         }
  48.         RectangleDrawer drawRect = new RectangleDrawer();
  49.         Rectangle.addActionListener(drawRect);
  50.        
  51.         class LineDrawer implements ActionListener
  52.         {
  53.             @Override
  54.             public void actionPerformed(ActionEvent e)
  55.             {
  56.                 graphcomp.addLine();
  57.             }
  58.         }
  59.         LineDrawer drawLine = new LineDrawer();
  60.         Edge.addActionListener(drawLine);
  61.        
  62.         class EllipseDrawer implements ActionListener
  63.         {
  64.             @Override
  65.             public void actionPerformed(ActionEvent e)
  66.             {
  67.                 graphcomp.addEllipse();
  68.             }
  69.         }
  70.         EllipseDrawer drawEllipse = new EllipseDrawer();
  71.         Ellipse.addActionListener(drawEllipse);
  72.        
  73.         class LabelSetter implements ActionListener
  74.         {
  75.  
  76.             @Override
  77.             public void actionPerformed(ActionEvent e)
  78.             {
  79.                 graphcomp.addLabel(Text.getText());
  80.             }      
  81.         }
  82.         LabelSetter setLabel = new LabelSetter();
  83.         Label.addActionListener(setLabel);
  84.        
  85.         frame.add(panel, BorderLayout.NORTH);
  86.        
  87.         frame.add(graphcomp);
  88.            
  89.         frame.setVisible(true);
  90.     }
  91.  
  92.  
  93.    
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment