Como tiro o "JOptionPane"?

6 respostas
A

Olá,
estou tentando tirar a parte do JOptionPane e deixar apenas o g.drawOval() :roll:

ShapesTest.java

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class ShapesTest
{
	public static void main(String args[])
	{
		String input = JOptionPane.showInputDialog("Enter 1 to draw rectangles\n" + "Enter 2 to draw ovals");
		
		int choice = Integer.parseInt(input);
		
		Shapes panel = new Shapes(choice);
		
		JFrame application = new JFrame();
		
		application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		application.add(panel);
		application.setSize(300, 300);
		application.setVisible(true);
		
	}
	
}

Shapes.java

import java.awt.Graphics;
import javax.swing.JPanel;

public class Shapes extends JPanel
{
	private int choice;
	
	public Shapes(int userChoice)
	{
		choice = userChoice;
	}
	
	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
		for (int i = 0;i<10;i++)
		{
			switch(choice)
			{
				case 1:
					g.drawRect(10+i*10, 10+i*10, 50+i*10, 50+i*10);
					break;
				case 2:
					g.drawOval(10+ i*10, 10+i*10, 50 + i*10, 50 +i*10);
				
			}
			
		}
	}
}

Obrigada :)

6 Respostas

Andre_Rosa

Qual é a sua intenção? E porque você quer “tirar” o JOptionPane? Por favor, defina também o que você quer dizer com “tirar”.

A

Estou tentando fazer o seguinte exercício:

Andre_Rosa

Sim, mas o que têm a ver com “tirar” o JOptionPane? Você sabe o que é o JOptionPane?

A

Na verdade, quero tirar as opções de selecionar o retângulo ou o oval, e deixá-lo apenas com o oval.
Tentei tirar a variável "choice", e modificar algumas partes. Mas não deu certo.

Este é o modificado:

import javax.swing.JFrame;

public class ShapesTest
{
	public static void main(String args[])
	{
		Shapes panel = new Shapes();
		
		JFrame application = new JFrame();
		
		application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		application.add(panel);
		application.setSize(300, 300);
		application.setVisible(true);
		
	}
}

ShapesTest

import java.awt.Graphics;
import javax.swing.JPanel;

public class Shapes extends JPanel
{
	public static void Shapes();
	
		public void paintComponent(Graphics g)
		{
			super.paintComponent(g);
		
			for(int i=0; i<10;i++)
			{
				g.drawOval(10 + i*10, 10 + i*10, 50 + i*10, 50 + i*10);
			}
		
		}
}
Andre_Rosa

Você se esqueceu de remover o:

public static void Shapes();

Ficaria assim:

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class ShapesTest
{
	public static void main(String args[])
	{
		
		Shapes panel = new Shapes();
		
		JFrame application = new JFrame();
		
		application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		application.add(panel);
		application.setSize(300, 300);
		application.setVisible(true);
		
	}
	
}
import java.awt.Graphics;
import javax.swing.JPanel;

public class Shapes extends JPanel
{

	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
		for (int i = 0;i<10;i++)
		{

                    g.drawOval(10+ i*10, 10+i*10, 50 + i*10, 50 +i*10);
				
		
		}
	}
}
A

Obrigada!
Problema resolvido :smiley:

Criado 11 de julho de 2011
Ultima resposta 11 de jul. de 2011
Respostas 6
Participantes 2