Java Package - To create a button and import one when needed.

Posted by Zopyrus on Stack Overflow See other posts from Stack Overflow or by Zopyrus
Published on 2010-04-09T23:21:52Z Indexed on 2010/04/09 23:33 UTC
Read the original article Hit count: 275

Filed under:
|
|
|

This is more like a package/import test. We'll start with my base folder at .../javaf/test.java

My goal is to create subcategory and create a class with a button that I can import to test.java when I need a button. I feel like I've done it right, I know that the button doesn't do anything as of now, but I just want to make the whole thing work and expand the code thereafter. So here goes - This is test.java

import paket.*;  // importing classes from subcategory paket!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;


public class test {

    public test() {
        JFrame myFrame;
        JPanel myPanel;
        myFrame = new JFrame("Hello FramWorld");
        myPanel = new JPanel();

        // Here I want to add the object created in paket/myButts.java
        // The problem is how to make these two lines work.
        myButts myButton = new myButts();
        myPanel.add(myButton);


        myFrame.setVisible(true);
        myFrame.getContentPane().add(myPanel, BorderLayout.CENTER);
        myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        myFrame.pack(); 
    }

    public static void main(String args[]) {
        new test();
    }
}

And here is my .../javaf/paket/myButts.java

package paket; // Here is the package function (ought to work like a link)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

// This class should only create a button.

public class myButts {  
    public myButts() {
        JButton myButt = new JButton();
    }
}

I've compiled myButts.java with no errors. But then I compile test.java and it gives me the following error:

test.java:19: cannot find symbol symbol : method add(paket.myButts) location: class javax.swing.JPanel myPanel.add(myButton);

Thanks for reading, Z

© Stack Overflow or respective owner

Related posts about java

Related posts about package