Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Adding container's parent to itself

843806May 1 2008 — edited May 3 2008
Hello everyone,

I have a program that supposed to open a Swing window and create three tabs for calculating Factorials, Permutations, and Combinations.

Once you click on one of those tabs, text boxes and a button will appear. You type in the numbers, and it will give the desired calculations for you.

I compiled this program and it was successful, but when I tried to run it, I got this error message:

Exception in thread "main" java.lang.IllegalArgumentException: adding container'
s parent to itself
at java.awt.Container.addImpl(Container.java:1017)
at java.awt.Container.add(Container.java:903)
at newFactorialsGUI.<init>(newFactorialsGUI.java:40)
at newFactorialsGUI.createAndShowGUI(newFactorialsGUI.java:50)
at newFactorialsGUI.main(newFactorialsGUI.java:172)

I am probably making some painfully obvious and stupid mistake; but please excuse me, I am fairly new to Java.

If anybody can tell me what I did wrong and how I can fix so, that would be great. Thank you (and please excuse the bizarre variable and constructor names).
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.JComponent;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.BoxLayout;
import javax.swing.Box;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.SwingUtilities.*;
import java.beans.*;

public class newFactorialsGUI extends JFrame
{
	JLabel informationarea;
	JFrame frame;
	String heading1 = "Enter the number that goes before the ! now:";
	String heading2 = "Enter the numbers that go before and after the P now:";
	String heading3 = "Enter the numbers that go before and after the C now:";
	public newFactorialsGUI(JFrame frame)
	{
		this.frame = frame;
		informationarea = new JLabel("Select a tab, then enter the numbers and this program will calculate it for you.", JLabel.CENTER);
		Border padding = BorderFactory.createEmptyBorder(20,20,5,20);
		JPanel allincommonpanel = new JPanel();
		allincommonpanel.setBorder(padding);
		JTabbedPane Cardamon = new JTabbedPane();
		Cardamon.addTab("Factorials", null, allincommonpanel, heading1);
		Cardamon.addTab("Permutations", null, allincommonpanel, heading2);
		Cardamon.addTab("Combinations", null, allincommonpanel, heading3);
		allincommonpanel.add(Cardamon, BorderLayout.CENTER);
		allincommonpanel.add(informationarea, BorderLayout.PAGE_END);
		informationarea.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		createFactorialBox();
		createPermutationBox();
		createCombinationBox();
	}
	public static void createAndShowGUI()
	{
		JFrame frame = new JFrame("Factorials, Permutations, and Combinations Calculator");
		new newFactorialsGUI(frame);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
	public int factorialize(int inputfactorial)
	{
		int factorialfinale = 1;
		int factorialengine;
		for (factorialengine = inputfactorial; factorialengine >= 1; factorialengine--)
		{
			factorialfinale *= factorialengine;
		}
		return factorialfinale;
	}
	public int permutationize(int inputpermutation1, int inputpermutation2)
	{
		int permutationsfinale = 1;
		int rununtil;
		rununtil = inputpermutation1 - inputpermutation2;
		rununtil++;
		int permutationsengine;
		for (permutationsengine = inputpermutation1; permutationsengine >= rununtil; permutationsengine--)
		{
			permutationsfinale *= permutationsengine;
		}
		return permutationsfinale;
	}
	public int combinationize(int inputcombination1, int inputcombination2)
	{
		int combinationsqualify = 1;
		int rununtil;
		rununtil = inputcombination1 - inputcombination2;
		rununtil++;
		int comboengine1;
		int combinationsqualify1 = 1;
		for (comboengine1 = inputcombination1; comboengine1 >= rununtil; comboengine1--)
		{
			combinationsqualify1 *= comboengine1;
		}
		int comboengine2;
		int combinationsqualify2 = 1;
		for (comboengine2 = inputcombination2; comboengine2 >= 1; comboengine2--)
		{
			combinationsqualify2 *= comboengine2;
		}
		int combinationsfinale = combinationsqualify1 / combinationsqualify2;
		return combinationsfinale;
	}
	void setLabel(String newtxt)
	{
		informationarea.setText(newtxt);
	}
	private void createFactorialBox()
	{
		JPanel controlpanel2 = new JPanel();
		controlpanel2.setLayout(new BorderLayout());
		final JTextField input = new JTextField(15);
		JButton buttonOK = new JButton("Calculate");
		controlpanel2.add(input);
		controlpanel2.add(buttonOK);
		buttonOK.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				String rawinput = input.getText();
				int finalinput = Integer.parseInt(rawinput);
				int answerfinale =  factorialize(finalinput);
				setLabel("The answer to your factorial problem is: " + answerfinale);
			}
		}
		);
	}
	private void createPermutationBox()
	{
		JPanel controlpanel1 = new JPanel();
		controlpanel1.setLayout(new BorderLayout());
		final JTextField input1 = new JTextField(15);
		final JTextField input2 = new JTextField(15);
		JButton buttonOK = new JButton("Calculate");
		controlpanel1.add(input1);
		controlpanel1.add(input2);
		controlpanel1.add(buttonOK);
		buttonOK.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				String rawinput1 = input1.getText();
				int finalinput1 = Integer.parseInt(rawinput1);
				String rawinput2 = input2.getText();
				int finalinput2 = Integer.parseInt(rawinput2);
				int answerfinale = permutationize(finalinput1, finalinput2);
				setLabel("The answer to your permutation problem is: " + answerfinale);
			}
		}
		);
	}
	private void createCombinationBox()
	{
		JPanel controlpanel3 = new JPanel();
		controlpanel3.setLayout(new BorderLayout());
		final JTextField input1 = new JTextField(15);
		final JTextField input2 = new JTextField(15);
		JButton buttonOK = new JButton("Calculate");
		controlpanel3.add(input1);
		controlpanel3.add(input2);
		controlpanel3.add(buttonOK);
		buttonOK.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				String rawinput1 = input1.getText();
				int finalinput1 = Integer.parseInt(rawinput1);
				String rawinput2 = input2.getText();
				int finalinput2 = Integer.parseInt(rawinput2);
				int answerfinale = combinationize(finalinput1, finalinput2);
				setLabel("The answer to your combination problem is: " + answerfinale);
			}
		}
		);
	}
	public static void main(String[] args)
	{
		createAndShowGUI();
	}
}

Comments

EdStevens
cayenne wrote:
Hi Folks,
I just cannot seem to find anything readily in MOS at Oracle...

I understand that these days, the patches they put out are no longer just fixes to pieces of the database, but for some reason, they are now full blown installs.

So, rather than download from OTN and install and then have to patch...I'd rather go to MOS and download the patch and install that as my fresh database install.

My trouble is, I can't find the darned thing looking through the patch area, without knowing the patch number..etc.
I feel your pain and really can't offer any advice on that. Searching for patches has been a continual source of frustration for me.
What do ya'll do when wanting to find the latest version for a fresh install?

A further question..how are ya'll treating this new patch paradigm where they seem to expect you to do fresh installs just to patch up a level? Do you all have the resources to do a new install and migrate over...or do you migrate in place which the documentation seems to warn your off from doing?
Once you download the patch/full install and unzip it, look for the 'readme' files. The installer should detect or ask if you are doing a patch and handle the 'upgrade' conversion for you. At least it does when upgrading Grid Infrastructure. I'll find out about databases next week. ;-)

>
Thanks in advance,

cayenne
Srini Chavali-Oracle
Pl see these MOS Docs

Quick Reference to RDBMS Database Patchset Patch Numbers [ID 753736.1]
Quick Reference To Patch Numbers For Database PSU, SPU(CPU) And Bundle Patches [ID 1454618.1]

There are advantages to an out-of-place upgrade - you can install the software while the instance is up and running, thus limiting your downtime. It also allows for a quick downgrade if that should ever be needed.

Important Changes to Oracle Database Patch Sets Starting With 11.2.0.2 [ID 1189783.1]

HTH
Srini
Helios-GunesEROL
Hi;

Please also refer:
Oracle Recommended Patches -- Oracle Database [ID 756671.1]
NOTE:430449.1 - How to find DB Patches for the Microsoft Windows platforms My Oracle Support

Regard
Helios
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 31 2008
Added on May 1 2008
8 comments
3,874 views