Tenho essa parte do código que executa um paint…
Criei na guia Arquivo, um item “Clear” para limpar a tela… mas como fazer isso???
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;
class Main {
/**
*
*/
private static final long serialVersionUID = 1L;
static Quadro q;
static JFrame f = new JFrame();
static Container quadro = f.getContentPane();
static EscolheFormato escolheFormato = new EscolheFormato();
@SuppressWarnings("deprecation")
public static void main(String[] args) {
colocandoBarraEItens();
adicionandoBotaoDePoligonos();
q = new Quadro();
f.setBackground(Color.WHITE);
f.setCursor(Cursor.CROSSHAIR_CURSOR);
f.setTitle("Paint em Java");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(800, 600);
f.setResizable(false);
f.getContentPane().add(q);
f.setVisible(true);
}
private static void adicionandoBotaoDePoligonos() {
JToolBar tool = new JToolBar();
JButton ova = new JButton("Oval");
ova.setLocation(0, 35);
ova.setSize(90, 35);
JButton quad = new JButton("Quadrado");
ova.addActionListener(escolheFormato);
quad.setLocation(0, 0);
quad.setSize(90, 35);
quad.addActionListener(escolheFormato);
JButton reta = new JButton("Reta");
reta.setLocation(0, 70);
reta.setSize(90, 35);
reta.addActionListener(escolheFormato);
JButton pol = new JButton("Poligono");
pol.setLocation(0, 105);
pol.setSize(90, 35);
pol.addActionListener(escolheFormato);
tool.setSize(800, 35);
tool.add(ova);
tool.add(quad);
tool.add(reta);
tool.add(pol);
f.add(tool);
}
private static void colocandoBarraEItens() {
JMenuBar barra = new JMenuBar();
JMenu guia = new JMenu("Arquivo");
JMenuItem item = new JMenuItem("Sair");
JMenuItem item1 = new JMenuItem("Clear");
guia.add(item1);
item1.addActionListener(new Ouve0GUI(f));
f.setJMenuBar(barra);
barra.add(guia);
guia.add(item);
item.addActionListener(new SairDoPrograma());
}
}//
class Ouve0GUI implements ActionListener {
Component parentComponent;
Ouve0GUI(Component parentComponent) {
this.parentComponent = parentComponent;
}
public void actionPerformed(ActionEvent e) {
/*
O QUE FAZER PARA LIMPAR A TELA???
*/
}
}//