hi everyone .. I hope to help me :) ..
i have java code.. the main idea of it the user selected from menu the equation (liner - Cubic - Quadratic ) need of them and then user enter the value of x and y and then draw
the main problem of the code can not accept the value and then can not draw :'(
and this my code u can run it and discover the error ..

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class EMnue extends JApplet implements ActionListener  {
	JMenuBar menuBar;
	
	JMenu fileMenu;
	
	JMenuItem menuItem,menuItem2,menuItem3;
	
	
    JTextField text1=new JTextField (5);
    JTextField text2=new JTextField (5);
 
    JLabel l1=new JLabel("Enter X");
    JLabel l2=new JLabel("Enter Y");
    
    LinePanel panel= new LinePanel();
   
    public EMnue() {
    }
    public void init(){
       	JPanel p=new JPanel();
      	JButton b=new JButton("Draw");
    	p.setLayout(new FlowLayout());
       	 p.add(l1);
         p.add(text1);
         p.add(l2);
         p.add(text2);
         p.add(b);
        b.addActionListener(this);
         menuBar=new JMenuBar();
         menuBar.setLayout(new BoxLayout(menuBar,BoxLayout.X_AXIS)) ;
         fileMenu=new JMenu("Equations");
         menuBar.add(fileMenu);
       	menuItem = new JMenuItem("LineEqautions");
       	fileMenu.add(menuItem);
		setJMenuBar(menuBar);
		menuItem.setActionCommand("L1");
		menuItem.addActionListener(this);
			menuItem2 = new JMenuItem("CubicEqautions");
		menuItem2.setActionCommand("L1");
		menuItem2.addActionListener(this);
		fileMenu.add(menuItem2);
		setJMenuBar(menuBar);
			menuItem3 = new JMenuItem("QuadraticEqautions");
		menuItem3.setActionCommand("L1");
		menuItem3.addActionListener(this);
		fileMenu.add(menuItem3);
		setJMenuBar(menuBar);
		//this.getContentPane().add( new BorderLayout());
        this.getContentPane().add(p, BorderLayout.NORTH);
       // this.getContentPane().add(panel, BorderLayout.CENTER);
     	
    	
    }
    public void actionPerformed(ActionEvent e){
    	if((e.getActionCommand()).equals("l1")){
    		
    		
    		String str1=text1.getText();
    		String str2=text2.getText();
    		panel.x=Integer.parseInt(str1);
    		panel.y=Integer.parseInt(str2);
    		
    	}
    }
    
    public static void main(String s[]){
        	JFrame frame=new JFrame();
        	EMnue applet=new EMnue();
    		applet.init();
    		frame.getContentPane().add(applet);
    		frame.pack();
    		frame.setVisible(true);
    	
    }
    
    
}
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class LinePanel extends JPanel {
    public int x;
    public int y;
    int point=1000;


    public LinePanel() {
    
    }
    public void paintComponent(Graphics g)

    {

     super.paintComponent(g)                                                                                                                                                                                                                                                                                                                                                                                                                                                          ;

     Graphics2D g2 = (Graphics2D) g;

       

    g2.translate(200,200);

     int x1=x;
     int y1=y;
    int x2,y2;

    for(int i=0;i<point;i++)

    {x2=i;

    y2=x*x1+y;

    g2.drawLine(x1,y1,x2,y2);

    x1=x2;

    y1=y2;

    }
    }
}

note : My code is not yet complete .. I did not write an equation for the square and cubic


thanks for all:)

package com;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class EMnue extends JApplet implements ActionListener  {
	JMenuBar menuBar;
	
	JMenu fileMenu;
	
	JMenuItem menuItem,menuItem2,menuItem3;
	
	
    JTextField text1=new JTextField (5);
    JTextField text2=new JTextField (5);
 
    JLabel l1=new JLabel("Enter X");
    JLabel l2=new JLabel("Enter Y");
    
    LinePanel panel= new LinePanel();
 	JButton b;
 	JFrame frame;
    public EMnue(JFrame frame) {
    	this.frame=frame;
    }
    public void init(){
    	setLayout(new BorderLayout());
       	JPanel p=new JPanel();
     b=new JButton("Draw");
    	p.setLayout(new FlowLayout());
       	 p.add(l1);
         p.add(text1);
         p.add(l2);
         p.add(text2);
         p.add(b);
        b.addActionListener(this);
         menuBar=new JMenuBar();
         menuBar.setLayout(new BoxLayout(menuBar,BoxLayout.X_AXIS)) ;
         fileMenu=new JMenu("Equations");
         menuBar.add(fileMenu);
       	menuItem = new JMenuItem("LineEqautions");
       	fileMenu.add(menuItem);
		setJMenuBar(menuBar);
		menuItem.setActionCommand("L1");
		menuItem.addActionListener(this);
			menuItem2 = new JMenuItem("CubicEqautions");
		menuItem2.setActionCommand("L1");
		menuItem2.addActionListener(this);
		fileMenu.add(menuItem2);
		setJMenuBar(menuBar);
			menuItem3 = new JMenuItem("QuadraticEqautions");
		menuItem3.setActionCommand("L1");
		menuItem3.addActionListener(this);
		fileMenu.add(menuItem3);
		setJMenuBar(menuBar);
		//this.getContentPane().add( new BorderLayout());
        this.getContentPane().add(p, BorderLayout.NORTH);
       // this.getContentPane().add(panel, BorderLayout.CENTER);
        this.getContentPane().add(panel, BorderLayout.CENTER);
     	
    	
    }
    public void actionPerformed(ActionEvent e){
    	if(e.getSource()== b){
    		
    		//remove(panel);
    		String str1=text1.getText();
    		String str2=text2.getText();
    		System.out.println(str1);
    		System.out.println(str2);
    		// create panel object
    		LinePanel panel= new LinePanel();
    		panel.x=Integer.parseInt(str1);
    		panel.y=Integer.parseInt(str2);
    		//panel.repaint();
    		//add new panel to the frame
    	 this.getContentPane().add(panel, BorderLayout.CENTER);
    		   
    		 validate();
    		 
    		
    	}
    }
    
    public static void main(String s[]){
        	JFrame frame=new JFrame();
        	EMnue applet=new EMnue(frame);
    		applet.init();
    		frame.getContentPane().add(applet);
    		//frame.pack();
    		frame.setVisible(true);
    	
    }
    
    
}


 class LinePanel extends JPanel {
    public int x;
    public int y;
    int point=1000;


    public LinePanel() {
    
    }
    public void paintComponent(Graphics g)

    {

     super.paintComponent(g)                                                                                                                                                                                                                                                                                                                                                                                                                                                          ;

     Graphics2D g2 = (Graphics2D) g;

    g2.translate(200,200);

     int x1=x;
     int y1=y;
    int x2,y2;

    for(int i=0;i<point;i++)

    {x2=i;

    y2=x*x1+y;

    g2.drawLine(x1,y1,x2,y2);

    x1=x2;

    y1=y2;

    }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.