Jump to content

Java Using Netbeams 7.0.1


bigjoe11a

Recommended Posts

Posted Yesterday, 08:12 PMI just downloaded and installed netbeams and I watched some video tutorials on creating forums. How ever I have been able to find a video on adding mysql database to it and any thing like it. So I wanted to see if some one here could help.The other problem is that I created a new forum, a jframe form. and this video I watched told me to do some think like this.

public class EditTopic {    /**         * @param args the command line arguments         */    public static void main(String[] args) {            // TODO code application logic here            EditTopic edit = new EditTopic();            edit.setVisible(true);                           }}

How ever the problem is that the command called "edit.setVisible(true);" doesn't work. I can't conpile it. I'm using netbeams 7.0.1 for windows. when I run this. It should show my form. and well like I said, I can't even compile it. Joe

Link to comment
Share on other sites

Suppose u use MySQL, so install MySQL first, then try this link for configuration http://netbeans.org/.../ide/mysql.html About the second, I dont sure that I often see this type of code, maybe have this in your main function

public static void main(String[] args){JFrame frame = new JFrame("TitleLessJFrame");frame.getContentPane().add(new JLabel(" HEY!!! LOOK AT ME, I DON'T HAVE MY TITLE BAR..."));//This is the method that does the magic of removing titleframe.setUndecorated(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);]frame.setSize(400, 200);frame.setVisible(true);}

Link to comment
Share on other sites

On this line you have

frame.setVisible(true);

The command that your using setVisible doesn't work. It errors out tell me that the setVisible does not exist.

Link to comment
Share on other sites

Hi import javax.swing.JFrame :)

 package test;import javax.swing.JFrame;import javax.swing.JLabel;/*** This program creates a JFrame without a Title bar*/public class TitlelessFrame{public static void main(String[] args){JFrame frame = new JFrame("TitleLessJFrame");frame.getContentPane().add(new JLabel(" HEY!!! LOOK AT ME, I DON'T HAVE MY TITLE BAR..."));//This is the method that does the magic of removing titleframe.setUndecorated(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(400, 200);frame.setVisible(true);}}

Sorry I miss EXIT_ON_CLOS E (a blank space!!!)

Link to comment
Share on other sites

Nope, Sorry that didn't work as well, I uploaded an image so you can see what's is happening, Joe

post-13255-0-76059900-1324527353_thumb.jpg

Link to comment
Share on other sites

I see, the problem here is your code, I think it is basic, the class has main() function is EditTopic, in your main() function, u create new EditTopic(), that is impossible (or u must have constructor for the EditTopic itself inside EditTopic class).Which class contains your JFrame, create a new one with that class type! Like this, Class JFrameTest

 package javaapplication1; import javax.swing.JFrame;import javax.swing.JLabel; public class JFrameTest {    public JFrameTest(){        JFrame frame = new JFrame("TitleLessJFrame");        frame.getContentPane().add(new JLabel(" HEY!!! LOOK AT ME, I DON'T HAVE MY TITLE BAR..."));        //This is the method that does the magic of removing title        frame.setUndecorated(true);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.setSize(400, 200);        frame.setVisible(true);    }}

Class Main

 package javaapplication1;public class Main{    public static void main(String[] args) {        JFrameTest frame = new JFrameTest();    }}

Link to comment
Share on other sites

I'm sorry, I don't under stand, Can you show me what to do. I never use this software before.I guess the video tutorials I see on youtube are not all right or work like they should.

Link to comment
Share on other sites

Okie :) Start with new one1. File -> New Project ... -> Java -> Java Application (suppose project name is javaapplication1)2. Now put all the code from Main class I refer above into the Main.java file that Netbean just created3. Right click on package javaapplication1, choose New Java Class, named it JFrameTest, and put that equivalent above code4. Build and Run it

Link to comment
Share on other sites

I'm sorry Smiles, I don't under stand. I never did this before. any chance you can attach a sample for me. So I can see what you did.I all so fount out that then I used all the default names when I create a new project and add a JFrame to it. It works. How ever when I change the names for the project and for the JFrame. Then it doesn't work. So I'm confused on this. UPDATE Here the link for the video that showed me how to do what I wanted to do. So this should give you an idea on what I was trying to do

Link to comment
Share on other sites

Suppose u use MySQL, so install MySQL first, then try this link for configuration http://netbeans.org/.../ide/mysql.html About the second, I dont sure that I often see this type of code, maybe have this in your main function
public static void main(String[] args){JFrame frame = new JFrame("TitleLessJFrame");frame.getContentPane().add(new JLabel(" HEY!!! LOOK AT ME, I DON'T HAVE MY TITLE BAR..."));//This is the method that does the magic of removing titleframe.setUndecorated(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);]frame.setSize(400, 200);frame.setVisible(true);}

Any all the link you gave me. It doesn't tell me how the code is. How do I code the java to get the info I need or how to do an INSERT or UPDATE..
Link to comment
Share on other sites

Okey, when u change the name of the project, it not affect at all. But if u change the java file's name, u must change the class name also.For i.e, Main.java -> Something.javathen in the content of the new Something.javapublic class Main {...} -> public class Something() {...} You may try these tutorial (also, may I suggest u using Eclipse instead, Netbean is just strong in building interface)http://www.youtube.com/results?search_query=Java+Programming+Tutorial&oq=Java+Programming+Tutorial&aq=f&aqi=&aql=&gs_sm=e&gs_upl=0l0l0l351l0l0l0l0l0l0l0l0ll0l0 With database, you may check this link http://www.roseindia.net/jdbc/jdbc.shtml (also, Eclipse is choosed IDE) About interacting with database, u first install MySQL (I mostly use it, user is root and pass is 123456), create a database named 'test', a table named 'person' with three columns id - INTEGER - auto incrementage - VARCHARname - VARCHAR Create a new project, in the main() function, testing this code

 package javaapplication1;import java.sql.*; public class Main {    public static void main(String[] args) {        System.out.println("Inserting values in Mysql database table!");        Connection con = null;        String url = "jdbc:mysql://localhost:3306/test";        String user = "root";        String pwd = "123456";        String driver = "com.mysql.jdbc.Driver";        try {            Class.forName(driver);            con = DriverManager.getConnection(url,user,pwd);            try {                Statement st = con.createStatement();                int val = st.executeUpdate("INSERT person(age, name) VALUES ('99','test')");                System.out.println("1 row affected");            } catch (SQLException s){                System.out.println(s.getMessage());                System.out.println("SQL statement is not executed!");            }        } catch (Exception e){            e.printStackTrace();        }    }}

The first time compile this code will get error, u must download JDBC (an API allow connecting database) http://dev.mysql.com/downloads/connector/j/Unzip it, u will find a jar file inside (mysql-connector-java-{version}-bin.jar)Now, back to your project, right click on it, choose Properties -> Library -> Compile tab, click on Add Jar/Folder, browse to above file, choose it, now rebuild your code and run it :)

Link to comment
Share on other sites

Thanks Smiles. How ever I haven't been able to add the mysql library to eclipse.

Now, back to your project, right click on it, choose Properties -> Library -> Compile tab, click on Add Jar/Folder, browse to above file
I attached an image so you can see what I mean. There is no option for library, I'm going to see if I can do the same for Netbeams. Let me explain to you just wanted I'm looking for. On my web site I wanted to option for users to click on a link or button that will let them edit a mysql record, 3 args will have to be passed so that the mysql table gets updated. I didn't want to have to create a new php script,page and class to do all of this for me. I thought doing it in java would be faster and it's been a pain in the butt. The part I'm talking about is the forums section I made. When each user creates a new topic or post. They have the option to edit their record. or even delete it. I just wanted to learn some thing new. UPDATE: Sorry this board won't let me attach images.
Link to comment
Share on other sites

UPDATE: I was able to get the library installed into Netbeams and I created a database and table from your code above and I added your code to this test project. and I'm not getting any errors. Just nothing happens. It should display some thing on the screen and it doesn't and it doesn't add the record to the table. So I'm all so lost on this. Joe

Link to comment
Share on other sites

Sure it doesn't show anything, the example just inserts record to the database (I tested it works), u must open MySQL (Workbench) to see whether the record ('99','test') inserted to 'test' database. In your case, I dont think Java is a good choice or even fast choice (at least, user must download JRE to run your Java web application, here is Java applet). Just simply, I don't know any server application type that both support PHP and Java (JSP), so your site's server is supporting PHP, no chance for java code works together. May I suggest u flash, it's really cool ^_^ After tried, tried ... you win anyway :rolleyes:

Link to comment
Share on other sites

I just wanted to tell you that it turned out to be the class again, It's very picky. But it does work. and Thanks Smiles. One more question How do I run this java from a PHP script or a HTML Page. That's on the only question I have left until after new years.

Link to comment
Share on other sites

-_- uhm ... never try it before, I do not recommend if u using Java applet for user input then push to database because Java applet has no long live at the moment. Try this link http://www.php.net/manual/en/java.examples.php, create s.th similar, build it and go to your new project folder location, get the .class file and put it in the same folder with your .php file (I think so!!!) Test your code in local computer (installed JDK, MySQL, PHP server) :)
Link to comment
Share on other sites

Thanks, How ever I'm not getting any errors. and I compiled it with no problem. It just doesn't do any thing. Maybe you should try it too. and see if you can get it to work. See all I'm trying to do is create a Java form that has 3 input fields. Subject, Tags and Message. Then when submitted it updates the mysql database. It should read from the mysql database and display the old information. and Then the user can type what ever needs to be changed and click the Update button. I just didn't think it would be this hard to create some thing as small as a Java form.If you come up with any ideas. PLEASE let me know.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...