Showing posts with label Java Swing Visible Or Not Visible Oval. Show all posts
Showing posts with label Java Swing Visible Or Not Visible Oval. Show all posts

Monday, June 24, 2024

Visible Or Not Visible Oval Java Swing

// Visible Or Not Visible Oval Swing

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;


public class draw extends JFrame implements ActionListener

{

JFrame f;

JButton b1,b2;


public draw()

{

f=new JFrame();


b1=new JButton("Visible");

b1.addActionListener(this);


b2=new JButton("Not Visible");

b2.addActionListener(this);


f.add(b1);

f.add(b2);


f.setLayout(new FlowLayout());

f.setDefaultCloseOperation(EXIT_ON_CLOSE);

f.setSize(500,500);

f.setVisible(true);

}

public void actionPerformed(ActionEvent ae)

{

if(ae.getSource()==b1)

{

Graphics g=f.getGraphics();

g.setColor(Color.RED);

g.fillOval(100,100,200,200);

}

if(ae.getSource()==b2)

{

Graphics g=f.getGraphics();

g.setColor(Color.WHITE);

g.fillRect(0,0,1500,1500);

}

}

public static void main(String args[])

{

new draw();

}


Output :-


                            If You Click Visible Button Then Oval Will Apper And 
                          If You Click Not Visible Button Then Oval Will Disapper.