Advertisement
gdog2u

Untitled

Sep 3rd, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* So basically, I made a simple calculator in my spare time. When I thought what else to do
  2. I decided to add a graphing function. I thought it might be a good way to learn about the
  3. paintComponent. The thing is though, I never REALLy learned about it, which would explain my
  4. current troubles
  5. */
  6. import java.awt.*;
  7. import java.awt.event.*;
  8. import javax.swing.*;
  9.  
  10.  
  11. public class ab extends JFrame implements ActionListener {
  12.    
  13.     JLabel yEqu = new JLabel("Y= ");
  14.     JTextField equation = new JTextField(20);
  15.     JButton graphB =new JButton("Graph");
  16.  
  17.     public static void main(String[] args0){
  18.         ab grapher = new ab();
  19.     }
  20.     public ab(){
  21.         this.setLocationRelativeTo(null);
  22.         this.setVisible(true);
  23.         this.setTitle("Grapher");
  24.         this.setSize(800,700);
  25.         this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  26.         this.setLayout(new FlowLayout());
  27.         this.add(yEqu);
  28.         this.add(equation);
  29.         this.add(graphB);
  30.             graphB.addActionListener(this);
  31.     }
  32.        
  33.     public void paintComponent(Graphics g){
  34.         super.paintComponents(g);
  35.         Graphics2D g2 = (Graphics2D)g;
  36.         g2.fillRect(100,200,300,100); //Just a test to see if it is working
  37.        
  38.     }
  39.  
  40.     public void actionPerformed(ActionEvent e) {
  41.         if(e.getSource() == this.graphB){
  42.             equation.setText("yay"); //ignore this. Just a test to see if the button was working
  43.            
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement