Skip to main content



      Home
Home » Newcomers » Newcomers » JFrame.add() will not accept JButton(Cannot figure out why JFrame will not accept my JButton)
JFrame.add() will not accept JButton [message #1729619] Sat, 16 April 2016 03:21
Eclipse UserFriend
I am trying to create a very simple java GUI application in Eclipse. I have created a class that extends JFrame and I am able to open the blank JFrame without any issues. When I try to add a JButton to the JFrame I get the error: The method add(Component) in the type Container is not applicable for the arguments (JButton). I have been reading examples of how to do this for hours now and every example looks like what I have already done so why doesn't it work. My code is shown below.

 public class MainForm extends JFrame
{
	private static final long serialVersionUID = 1L;

	public MainForm ()
	{
		super("   Encryption Suite");
		setLayout(new FlowLayout());
		setResizable(false);
		setSize(500, 200);
		//Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		//setLocation((dim.width - 500)/2, (dim.height-200)/2);
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		
		JButton btnRandomKeygen = new JButton("Random Keygen");
		//JButton btnEnDeCrypt = new JButton("Encrypt/Decrypt");
		//JButton btnChecksum = new JButton("MD5 Checksum");
		//JButton btnFileCompare = new JButton("File Compare");
		//JButton btnCryptanalysis = new JButton("Cryptanalysis");
		//JRadioButton rdBtnSub = new JRadioButton("Substitution");
		//JRadioButton rdBtnOnTmPd = new JRadioButton("One-Time Pad");
		
		add(btnRandomKeygen);
	}
}

public class EncryptionSuite 
{
	public static void main(String[] args)
	{
		final MainForm mainForm = new MainForm();
		mainForm.setVisible(true);
	}
}
Previous Topic:Installer and Java Detection
Next Topic:Missing Viewpoint on Eclipse Modeling Tools
Goto Forum:
  


Current Time: Sun Oct 26 09:32:31 EDT 2025

Powered by FUDForum. Page generated in 0.09435 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top