Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 07:21
Matthew Palmer is currently offline Matthew PalmerFriend
Messages: 1
Registered: April 2016
Junior Member
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: Thu Oct 22 07:35:43 GMT 2020

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

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

Back to the top