Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- public class GraphDrawViewer {
- /**
- * @param args
- */
- public static void main(String[] args) {
- final GraphDrawComponent graphcomp = new GraphDrawComponent();
- // TODO Auto-generated method stub
- JFrame frame = new JFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel panel = new JPanel();
- frame.setSize(720, 480);
- frame.setTitle("Graph Viewer");
- JButton Rectangle = new JButton ("Rectangle");
- JButton Ellipse = new JButton ("Ellipse");
- JButton Edge = new JButton ("Edge");
- JButton Label = new JButton ("Label");
- final JTextField Text = new JTextField(20);
- panel.add (Rectangle);
- panel.add (Ellipse);
- panel.add (Edge);
- panel.add (Label);
- panel.add (Text);
- class RectangleDrawer implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- graphcomp.addRectangle();
- }
- }
- RectangleDrawer drawRect = new RectangleDrawer();
- Rectangle.addActionListener(drawRect);
- class LineDrawer implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- graphcomp.addLine();
- }
- }
- LineDrawer drawLine = new LineDrawer();
- Edge.addActionListener(drawLine);
- class EllipseDrawer implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- graphcomp.addEllipse();
- }
- }
- EllipseDrawer drawEllipse = new EllipseDrawer();
- Ellipse.addActionListener(drawEllipse);
- class LabelSetter implements ActionListener
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- graphcomp.addLabel(Text.getText());
- }
- }
- LabelSetter setLabel = new LabelSetter();
- Label.addActionListener(setLabel);
- frame.add(panel, BorderLayout.NORTH);
- frame.add(graphcomp);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment