peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I have no problem getting an access token manually. Till now for developing I was fetching the access token manually but now I need to embed this process in my application as well. So I was wondering how should I make my application written in java to communicate with web browser which ask user to authorize my app, which in turn gives me a code which is then used by me in same http method to get the access token.,

By reading documentation!
Its all there and if you not willing to search, we will not be doing for you. You ask general question you get general answer

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You would best do to ask this question your supervisor as he/she should know best what they expect. Whole thing can be done with mocking framework and it will be fine with any other programmer because with poor problem description and low expectation there is so much you can do as programmer.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

There been some changes with Hibernate 3.5 and 3.6 so in many cases following many online tutorials will get you in trouble. My quick take on the problem:

  • With 3.5 and higher there is no more need for hibernate-annotations dependency as this is now packages as part of hibernate-core (check Hibernate documentation for setup and configuration)
  • With 3.6 AnnotationConfiguration is deprecate and you need to replace it with Configuration
    So previously used HibernateUtil class looking like
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.AnnotationConfiguration;
    
    public class HibernateUtil {
    
        private static final SessionFactory SESSION_FACTORY = buildSessionFactory();
    
        private static SessionFactory buildSessionFactory() {
            try {
                return new AnnotationConfiguration().configure().buildSessionFactory();
            } catch (Throwable ex) {
                throw new ExceptionInInitializerError(ex);
            }
        }
    
        public static SessionFactory getSessionFactory() {
            return SESSION_FACTORY;
        }
    }

    now looks as

    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
    
    public class HibernateUtil {
    
        private static final SessionFactory SESSION_FACTORY = buildSessionFactory();
    
        private static SessionFactory buildSessionFactory() {
            try {
                return new Configuration().configure().buildSessionFactory();
            } catch (Throwable ex) {
                throw new ExceptionInInitializerError(ex);
            }
        }
    
        public static SessionFactory getSessionFactory() {
            return SESSION_FACTORY;
        }
    }
  • In case of following error
    java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/MetadataProvider

    make sure that you are not using

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.3.0.ga</version>
    </dependency>

    that is reported as release by mistake with some bugs, but rather use

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.2.0.Final</version>
    </dependency>
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Ahhh this is why I wasn't aware of it (still on 3.3.2 ), there are some additional library now need it. Check this out

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Original post:

  1. moved to C++ section
  2. merged with double
  3. please do not advice on reposting in appropriate section, rather click Flag Bad Post and say "Please move to XYZ section" and a moderator will take care of it. We do not like to see double posted content
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You obviously trying to ride the wave of hot technologies, not taking in consideration if you have interest in the area and if you are actually capable of programming.

Many people do enter the development/programming field just failing out shortly disappointed/surprised by continuous learning curve that is expected of good dedicated programmer, thinking "I just finished my course/degree get a job and get paid for sitting behind pc, writing few lines of code and getting well paid". So think loud and tell as how do you fit in this, or we are just wasting our time and letting in another person after whom someone unlucky soul will have to clean all the junk code that you may write.

kvprajapati commented: Indeed! +15
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Sorry @Majestics, but your reputation comment for Ezzaral made me laugh little (no offence intended) as I expected that you actually try it this before you posted. However above suggestion will still produce similar looking but different at same time look&feels if you compare them on different OS.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

As Jeff already stated and you lamely down-voted you are expected to ask specific question and not just dump your assignment, even though you seems to tried to do something. Do not expect people to go through your code if you do not give clear directive of what you want/need/have problem with. We are not 24/7 coding service for homework, we know our stuff and we do not need to prove it. It is you who need to do it, as it is you who will be rewarded (marked) or blamed for the task not us.

Please rephrase your request or I will close it down.

mKorbel commented: good JeffGrigg has clear mind and big entusiazmus+1 +9
JeffGrigg commented: Why thank you for defending me against a lame down voting. ;-> +4
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

i coded it before to return data in that vector but when i saw that the JTable doesn't work with that vector i tried to just call it without using it. and i found that the JTable also don't work although it does nothing.
when i comment it.the JTable appears

That will be because your IDs() method gets only connection, create statement, but DOES NOT execute any query. Its like driving your car down to petrol station, park in front of pump and waiting to get it filled on its own.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

1) Welcome to forum
2) This sort of question is not welcome on the forum as it very simple and shows your lack of interest as you could have found it all this by your self if you look for it from google.
3) There is a sticky post on top of this forum section Starting mobile development [SDK / tutorials / resources / faq] where you can find a lot of resources
4) Android own web site holds clear example of step-by-step setup for first project in Eclipse, plus here is one for IntelliJ
5) Next time you post question you better to show some work on it, or it may get deleted

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

@Muralidharan.E

"We can remove particular object without using iterator also, In case if we dont know the size/contents of arraylist, then it is better to use iterator to avoid exception. So you have used iterator. Am i right peter_budo ? Or any other advantage is there to use Iterator in this scenario?"


Your approach would work properly only in case that you have no duplicates in collection so it would be safe to use in combination of any class implementing Set where there would be no duplicates. However in "raw" manner as you have now if you add second element ( Arrays.asList(23, 43, 40, 10, 43) )with same value you will only remove first instance

Muralidharan.E commented: Fine +3
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Use Iterator class

import java.util.*;

public class ArrayTest{

	public static void main(String[] args){
		List<Integer> numbers = new ArrayList<Integer>(Arrays.asList(23, 43, 40, 10));
		System.out.println("BEFORE DELETE " + numbers);
		for (Iterator<Integer> iterator = numbers.iterator(); iterator.hasNext();) {
		  Integer number = iterator.next();
		  if (number == 43) {
		      iterator.remove();
		  }
		}
		System.out.println("AFTER DELETE " + numbers);
	}
}
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

OK. Norm you were right about the 2d arrays. I tried it and it made my calculations go alot quicker and made the logic alot easier. Thanks

Then it would be nice if you reversed your dump down vote on his profile that you did, due to your ignorance of possible advice.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Possible is that you are using only Build Main Project(F11), where you should use Clean and Build Main Project(Shift+F11)

J-Dub commented: helped +1
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

What is the main benifit of using GWT in web applications?
>> For me no need to do all low level Ajax/JavaScript hacking

Is there any popular sites which has been developed by using GWT?
>> Little out of date article, but you can see few names there

Which is the best website to learn about GWT with easy examples?
>> I used official tutorial that gave me quick start, after that API is your friend (or you can invest in some book)

Muralidharan.E commented: Usefull Links +1
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

using JCreator.....

Your Applet must have been created in JCreator as Basic Java applet or it will not be run correctly on execution (old article but I think it is still right on execution). Work around can be by managing arguments in tools options as mentioned here

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Not so bad on programming since you spotted pattern of similarity, you can simplify it as follows

public void printPattern(String pattern, int maxIteration){
    for (j = 1; j <= maxIteration; j++) {
        System.out.print(pattern);
    }
}

and then in for loop

for (i = 1; i <= drawbox; i++) {
   printPattern("+---",i);
   printPattern("", i);
}

Even above can be simplified. Can you think of any way to organize all this string patterns and be able to simple to iterate through them?
Hint, collection and classes implementing this interface

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I have had this same question. Though I could not figure out how to get it to work you use Mysql and JDBC to make an online database on a server. you then connect to the server and write, or read from the database. please message me if you figure it out.

1) You can have DB enabled to receive connection from other sources then localhost which is default setup on most database instalations
2) You can provide service to which your desktop application will send request, this processed and DB queried, afteer that respond is generated and forwarded to client (your desktop application). This is commonly described as web service (The Java Web Services Tutorial)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Simple as that

mKorbel commented: very nice +1 +9
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

@andersonelnino DO NOT create multiple posts with same question, just because you are not getting answer fast enough. This is not 24/7 support for lazy students

For these wishing to follow this "enlightening" discussion can do so here.

Thread closed.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Kudos for NormR1 speed ;)

Please do not post "I'm new I need help" claiming to be new is just lame excuse for not trying.
JPanel extends JComponent that on other and extends Container, therefore you do inherit methods from there. Container has number of add() methods but following two can be of most interest to you add(Component comp) and add(String name, Component comp).

PS: Always try to read API for given class and try to understand what it can offer to you directly by declaration in it self, by inheritance.

mKorbel commented: Always try to read API +9
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Here is a list of Java Flash open source projects maybe you can find something suitable there.
From my point of view I was only interested in Project Capuchine, that was to get flash on JME platform, plus little of Java-Flex stuff

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You have no interesting information, just lunatic raving that was already deleted. Post on topic and with in the forum rules.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

@naveen p prakas
1) You just replied to old thread
2) You did not use code tags
3) You recommend to use old deprecated API

what can I say BAD, BAD, BAD for all 3

Thread closed before another time traveller descent on us.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You can write your own isInteger method like (

public boolean isInteger( String input )
{
   try
   {
      Integer.parseInt( input );
      return true;
   }
   catch( Exception e)
   {
      return false;
   }
}

or you can use patterns, but that can be overkill

mKorbel commented: why not :-) +9
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

This can usually can be achieved by Runtime class, I had a post on it few year back that you can see here. What you would have to do is execute application name and give it absolute file path. Secondly you can use something like JACOB library (small tutorial)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

1) Watch your attitude, it is not first time you asked a question with very little explanation and expecting immediate answer, coming back latter moaning that nobody is helping you. Questions get answered faster when we know what exactly person wish to achieve and not when we second guess what they actually mean to achieve.

2) So am I correct to assume you wish to call on some system installed application (Microsoft Office, Adobe Reader), providing file name and want to have it opened?

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You need to provider better description of what you want as above doesn't tell us anything.
>>How to open already present text file
File where on user system, on server, in memory?

>>So user can see the data in that file
See it where GUI view, in the browser, or some native application(Microsoft Office, Adobe Reader...)

>>I dont mean FileInput or OutputStream open
And what do you mean? We do not see on what sort of project you are working, or what is happening in your head so we would know what you about....

Given number of posts you already made one would expect higher quality of problem description instead of tree sentences.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Sometimes this is the issue with copy&paste, some characters do sneak in, even though they remind hidden to programmer eye. Best solution at times like that is write it line by line

PS: Thanx for reading that article :)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Off topic: @bobytch writing posts all in capital letters is considered as shouting and very rude. So please take it in consideration when you post next time

Salem commented: yes +17
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

thanx 4 de good rep..

One of the forum rules "Keep It Clear" states Do post in full-sentence English.
I hope I will not see you post again like showed above

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

For these whom may be interested in new stuff about Java 7 here is web broadcast from few days back Java 7 Celebration Webcats

PS: Didn't watch it yet so have no idea if any good :D

kvprajapati commented: :) Improved VM. It will run scala/jruby/groovy better. +15
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Have you ever tried to write tutorial, or lecture? Maybe perhaps presentation for your class? If you want to do it properly it does take time to write some decent tutorial. Code snippets are faster, but then they just small examples of code that we found "handy" and wanted to share with others.
We do have monthly newsletter, but that is only for internal purposes and for these that are interested. I regret, that Dani removed the link to newsletter archive and so far did not found it as a priority for adding it back, even though many of us asked for it.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

9 views means nothing. It could have been moderators checking for possible spam. Did you consider that?

Have look at this discussion @stackoverflow

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

@Majestics do not blame people for not giving you fast reply given the "extensive" problem description. Ezzaral tried and you slapped him with already solved
As for negative reputation, no big surprise. You ask question, come back in few hours "anybody home!?". We are not 24/7 coding service, we help when we can.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

I already solved it.......

So where is solution? Why you not sharing?

mKorbel commented: prevent agains down-voting +8
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

How about promote this great website on the social network, like Facebook, as you said, advertising it.Then Facebook FriendAdder Pro can do you great favor, because this program enables you to get quality targeted traffic.

Daniweb is already on Facebook, just search for it. Nevertheless from that side I would expect only another horde of lazy students to come and post homework requests for C/C++/Java/C#.
Daniweb is simply buffer place for start-up programmers (I'm excluding lazy students), unfortunately search for serious stuff will not land you here (more likely stackoverflow and other professional sites).

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Here is the code

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package project2;

/**
 *
 * @author nidhish
 */
public class Project2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
    }
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * strength.java
 *
 * Created on Jul 3, 2011, 10:11:41 PM
 */
package project2;
import java.awt.Choice;
import javax.swing.*;
/**
 *
 * @author nidhish
 */
public class page1 extends javax.swing.JFrame {
    public int val;
    int i2=21;
    
    public JLabel[] lb=new JLabel[25];
    public JLabel[] lba=new JLabel[25];
    public JLabel[] lbae=new JLabel[25];
    public JLabel[] lbael=new JLabel[25];
    public JLabel[] lbaels=new JLabel[25];
    public JLabel[] lbaelss=new JLabel[25];

    public Choice[] ch=new Choice[25];
    public Choice[] cho=new Choice[25];
    public Choice[] choi=new Choice[25];
    public Choice[] choic=new Choice[25];
    public Choice[] choice=new Choice[25];
    public Choice[] choices=new Choice[25];
    public page1() {
       
      initComponents();
              
       for(int f=1,j=90;f<=21;f++,j+=20)
       {
        ch[f] = new java.awt.Choice();
        ch[f].setBounds(60, j, 55, 20);
        jDesktopPane1.add(ch[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
 
        cho[f] = new java.awt.Choice();
        cho[f].setBounds(230, j, 55, 20);
        jDesktopPane1.add(cho[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
        
        choi[f] = new java.awt.Choice();
        choi[f].setBounds(400, j, 55, 20);
        jDesktopPane1.add(choi[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
        
        choic[f] = new java.awt.Choice();
        choic[f].setBounds(560, j, 55, 20);
        jDesktopPane1.add(choic[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
        
        choice[f] = new java.awt.Choice();
        choice[f].setBounds(720, j, 55, 20);
        jDesktopPane1.add(choice[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
        
        choices[f] = new java.awt.Choice();
        choices[f].setBounds(880, j, 55, 20);
        jDesktopPane1.add(choices[f], javax.swing.JLayeredPane.DEFAULT_LAYER);

            
        lb[f] = new javax.swing.JLabel(); 
        lb[f].setFont(new java.awt.Font("Tahoma", 1, 12));
        lb[f].setText("S1 S2");
        lb[f].setBounds(20, j, 36, 20);
        jDesktopPane1.add(lb[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
        
        lba[f] = new javax.swing.JLabel(); …
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
javaAddict commented: Always +13
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Usable, but not bullet-proof. What in case that file is called like "myfile.cvs.txt"?
You could possibly remedy this with endsWith(String suffix) .

Nevertheless there are better solutions like Apache Commons FilenameUtils.getExtension(String filename)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You normally don't. You either provide JAR file that can be executed from command line (or double click, but this often fails with Windows due to wrong registrations of execution services) or you provide it as WAR/EAR file that is deployed on some Java container/server

Many people specially students insists on creating exe files, which is possible with some additional often expensive tools. You can read about it here

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

To wide request. Did you had look at Oracle Reports Documentation, also includes Oracle Reports Java API Reference

mKorbel commented: patience +8
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Sorry I just spotted that you actually use PreparedStatement in both cases but you are using it wrong way. You still try to inject variables directly into SQL query while building string.
Something like this is error prone, you can easily mismatch opening and closing single or double quotes, or forget to include plus sign

String query1 = "UPDATE Info SET" 
                            + "lastname='"+jTable1.getValueAt(jTable1.getSelectedRow(), 1).toString()+"',"
                            + "firstname='"+jTable1.getValueAt(jTable1.getSelectedRow(), 2).toString()+"',"
                            + "middleI='"+jTable1.getValueAt(jTable1.getSelectedRow(), 3).toString()+"',"
                            + "age='"+jTable1.getValueAt(jTable1.getSelectedRow(), 4).toString()+"',"
                            + "course='"+jTable1.getValueAt(jTable1.getSelectedRow(), 5).toString()+"',"
                            + "school='"+jTable1.getValueAt(jTable1.getSelectedRow(), 6).toString()+"',"
                            + "contactno='"+jTable1.getValueAt(jTable1.getSelectedRow(), 7).toString()+"',"
                            + "contactno2='"+jTable1.getValueAt(jTable1.getSelectedRow(), 8).toString()+"' "
                            + "empbg='"+jTable1.getValueAt(jTable1.getSelectedRow(), 9).toString()+"',"
                            + "position='"+jTable1.getValueAt(jTable1.getSelectedRow(), 10).toString()+"',"
                            + "dateapplied='"+jTable1.getValueAt(jTable1.getSelectedRow(), 11).toString()+"',"
                            + "remarks='"+jTable1.getValueAt(jTable1.getSelectedRow(), 12).toString()+"',"
                            + "WHERE ID ="+jTable1.getValueAt(jTable1.getSelectedRow(), 0)+";";

where clean query declaration and then providing parameters is far better and more readable

String query1 = "UPDATE Info SET lastname=?, firstname=?, middleI=?, age=?, course=?, school=?, contactno=?, contactno2=?, empbg=?, position=?, dateapplied=?, remarks=? WHERE ID =?";
preparedStatement = conn.prepareStatement(query1);
preparedStatement.setString(1,person.getLasttName());
preparedStatement.setString(2, person.getFirstName());
preparedStatement.setString(3, person.getMiddleI());
preparedStatement.setString(4, person.getAge());
preparedStatement.setString(5, person.getCourse());
preparedStatement.setString(6, person.getSchool());
preparedStatement.setString(7, person.getContactNo());
preparedStatement.setString(8,person.getContactNo2());
preparedStatement.setString(9,person.empbg);
preparedStatement.setString(10,person.getPosition());
preparedStatement.setString(11,person.getDateApplied());
preparedStatement.setString(12,person.getRemarks());
preparedStatement.setString(13,person.getID());

As for mKorbel request to check for null, what he is trying to say is did you validated your form before your try to update database? Are you getting everything from form correctly? Are user provided data valid?(any case of cell returning null value)

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

You can let that baboon read this OpenOffice.org's Documentation of the Microsoft Excel File Format Excel Versions 2, 3, 4, 5, 95, 97, 2000, XP, 2003or Excel Binary File Format (.xls) Structure Specification

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Of course it is possible how would people actually put together POI or similar. Question is for you to answer to your self or your boss is it really worth to do it hard way...

For me answer is clear, use POI and just provide data to create Excel documents on the fly. I do not need to learn about Excel document format, don't have to come up with routines to insert data into cell, row, column etc.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

and where should i put that snippet? here is my code. thanks.

After line 78 build a proper data Collection expected by DefaultTableModel, meaning instead of looping and sending data directly to table you build up single object that you then pass to table model

mKorbel commented: excelent, agreed JTable is my favorite ... +8
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

To prevent further discussion and going off topic on use of comments, there are always two sides of coin.

One which says that you should write comments for methods, classes and generally places when you think it would be beneficial to others.

The other side is intentional naming and coding in the way that reader understand from method name, provided variable names and return what is the purpose of the method (same applies for classes, packages, etc). If you want to read more on that pick up Implementation Patterns or start new discussion.

Now we have to wait if OP will actual comeback with something else to ask/say

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Great idea to re-open old thread.
Closing down!

Salem commented: <burns>Excellent</burns> +0
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

Like this. Follow the tutorial and try out

mKorbel commented: by anonymous upvoter +8
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

To know exact exception would be most desired. Nevertheless I expect you failed to include db driver in classpath once you called your application from command line