I am making a simple GUI that will graph one of three parent functions (linear, quadratic, cubic) onto a graph based on the user's selection.
Looking at my code, I don't really have an issue with anything showing up except for the quadratic and cubic buttons. For some reason, they are invisible until you click the exact spot that they are located. I've never had this issue... Any help is greatly appreciated!
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class main extends JFrame{ functions functions = new functions(); int z = 11; int y = 11; JPanel panel = new JPanel(); JButton linear, quadratic, cubic; public main(){ setLayout(new FlowLayout()); panel = new JPanel(); panel.setLayout(new GridLayout(1,3)); add(panel); linear = new JButton("Linear"); panel.add(linear); quadratic = new JButton("Quadratic"); panel.add(quadratic); cubic = new JButton("Cubic"); panel.add(cubic); } public void paint(Graphics g){ for(int x = 0; x<20;x++){ g.setColor(Color.DARK_GRAY); g.drawLine(z, 0, z, 500); z += 20; } for(int x = 0; x<20;x++){ g.setColor(Color.DARK_GRAY); g.drawLine(0, y, 500, y); y += 20; } g.setColor(Color.BLACK); g.drawLine(250, 0, 250, 500); g.setColor(Color.BLACK); g.drawLine(0, 250, 500, 250); } public static void main(String args[]){ main frame = new main(); frame.setBackground(Color.WHITE); frame.setSize(500,500); frame.setVisible(true); frame.setResizable(false); frame.setTitle("Graph"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }