|
Eclipse and NetBeans are the best IDE for java.
NetBeans provide good interface like visual studio of Microsoft.
|
|
|
|
|
hey guys I need to learn java asap
I am studying java from this link : http://download.oracle.com/javase/tutorial/
everything given over here is theoretical. I am facing problems in grasping the concepts. Can u suggest me some programs or small projects that will make me learn the language efficiently.
Thanks in advance
|
|
|
|
|
Do you have any programming experience? If so take a small project you've done once and port it in Java.
What are you actually going to do? Java is a huge language and there are many areas. Start off by learning the core system - Standard Edition - as anything you learn there is portable to most of the other areas.
Do you understand OO? The early parts of the Java tutorials are theoretical because they need to be. As well as giving you the language, they are teaching you the theory and there is a lot of theory to take on board.
At the end of the day, if you do choose to go through the Java tutorials, you will get a very good knowledge of the language and it is free. Alternatively, you could buy one of the myriad books on the language.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
hi...yes i have done C++, c# and asp.net before.....i am finding difficulty in theory because we tend to forget when we move forward without making any programs...i have done basics but finding difficulty since interfacing part...please help
|
|
|
|
|
If you've done C# then most of Java should be straight forward.
By interfacing do you mean the concept of design to an Interface ?
Unlike C++ , Java only supports single-inheritance and interfaces allow a way around that. An Interface is used to define the capabilities of the class, not the function.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
|
Hi to all I have a problem in repainting my JPanel. I am creating a ShapeApplication program that can draw a shape on a click of a button. I have different classes in my application.
JPanel1 extends JPanel = use to draw different shape
JPanel2 extends JPanel= use to put my components such as buttons, label, and etc..
JFrame extends JFrame= use to put my JPanel1 and JPanel2
I have also normal classes which I implemented on my own
Shape = my Parent Class
Rectangle extends Shape = subclass of Shape and having an attribute of a Rectangle shape such as height and width
Square extend Shape = subclass of Shape and having an attribute of a Square shape such as height and width
My problem now is that when I use a repaint in actionPerformed method under my JPanel2 which contain my button component there is no effect on my drawing class which is my JPanel1 class
I implemented it this way
JPanel1.repaint();
I initialize my button's ActionListener like this..
button.addActionListener(this);//I am confuse what would be in the parameter.
Can you give a hint on this one? Where do I get wrong?
|
|
|
|
|
Hi,
JFrame is the container of JPanels (Jframe.add(child);)
JPanel1 with own event listener
JPanel2 with own event listener
You must call JPanel1.repaint() in event listener of JPanel 2
You must call JPanel2.repaint() in event listener of JPanel 1
-----------------------------------------------------
referenz_of_button.addActionListener // no action commands, but all action vvents
(
new ActionListener()
{public void actionPerformed(ActionEvent e) // e is placeholder form actionevent type (see Class ActionEvent)
{
// do something ony for object with referenz_of_button
}
}
);
JButton supports ActionListener
JLabel supports ActionListener
JButton and JLabel support MouseListener , KeyListener etc.
----------------------------------------------------
only if you want to use labels (action commands) of buttons
public void actionPerformed(ActionEvent event)
{
String cmd = event.getActionCommand(); // get label of button, label is the action command
if (cmd.equals("label_of_button1"))
{
// do something für button1
}
if (cmd.equals("label_of_button2"))
{
// do something für button1
}
}
referenz_of_button1.addActionListener(this);
// label of button must be "label_of_button1"
referenz_of_button2.addActionListener(this);
// label of button must be "label_of_button2"
JButton supports ActionListener
JLabel supports ActionListener
|
|
|
|
|
I am confuse about your statement below
JPanel1 with own event listener
JPanel2 with own event listener
You must call JPanel1.repaint() in event listener of JPanel 2
You must call JPanel2.repaint() in event listener of JPanel 1
Can you give me some example on this one just a short code. I really don't get it..
Hi here is my code of my actionPerformed under JPanel2
JPanel1 jpanel1 = new JPanel1();
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnOK) {
jpanel1.repaint();
}
}
|
|
|
|
|
Hello twseitex I manage to solve my issue on "Repaint JPanel problem in java". The problem is I just put all of my two classes (JPanel1 and JPanel2) directly on a JFrame which make my button doesn't send any event on my JPanel1 class because they are on separate classes. Yes your right I now understand what you mean on your statement.
JFrame is the container of JPanels (Jframe.add(child);)
JPanel1 with own event listener
JPanel2 with own event listener
You must call JPanel1.repaint() in event listener of JPanel 2
You must call JPanel2.repaint() in event listener of JPanel 1
This makes me think if I will just and my JPanel1 class on my JPanel2 class which handles all the event this will be done. In this case I will shorten my codes by not implementing each class with their own event listener and I am right I have fix the issue. This is really a great lesson for me as a newbie programmer.
If you want to see my initial ShapeApplication heres the link for the jar file Click Here
|
|
|
|
|
Hi,
JFrame have repaint from Component.
JPanel have repaint form JComponent,and Component.
Repaint JFrame (contianer) or repaint Jframes.
You want repaint JFrames. Change GUI of JPanel1 and call Jpanel1.repaint() ...
Same thing with other words.
To connect 2 JPanels in (a) different classes you must have references of this objects to create
a handler to manage events of this JPanels or (b) put all classes into same container class.
(a) Constructor create instancte of class.
Inside of class you can save pointer of class itself into a global variable.
Read out this variable after create instance of class: use a global function of
class to get pointer of class istself. And this pointer use for e.g. repaint() for this instance.
(b) Or put all classes into same container class.
I use (a) in my java audio player. 1 main class for audio, 1 main class for GUI (JPanels etc.).
1 main class for applet. Applet call constructors of Audio and GUI, and after call functions
of classes to get references of instances of audio and GUI and save this pointers inside of
applet class. To be shure that classes have a pointer i read out saved pointer in applet.
(Pointer default is null bevore instances of audio an GUI are created.) So applet class
can manage connections between Adio and GUI classes (instances).
And to connect this different classes i use references of instances. Other reason for that: I must
synchronize events of audio with events of GUI (e.g. change tooltip text of buttons if
audio change). It is for me not possbile to put all classes into same container class.
In Audio and GUI classes i use threads in own content of class. Mixing of ressources (like threads)
of classes not possible. And: If create of Audio instance and or GUI instance failed,
applet ends. This i check inside of applet class.
P.S. Sorry for my english. I come from germany.
|
|
|
|
|
I am a newbie in programming . I just research about an advance topic of this java programming language and I came cross this question and puzzled me.
What is tracking multiple instances?
What do this mean in java?
|
|
|
|
|
flashery wrote: What is tracking multiple instances? What do this mean in java?
As it stands, it means nothing.
If you can give a bit more detail about the context of the question, people may be able to shed some light.
|
|
|
|
|
Hi, if you mean "synchronized" see http://www.jguru.com/faq/view.jsp?EID=226112
|
|
|
|
|
hi there i am trying to implement a simple chatserver and when searching for examples i saw a synchronized statement which uses a variable as a lock of the block.. the code is this;
private List<Foo> myList = new ArrayList<Foo>();
private Map<String,Bar) myMap = new HashMap<String,Bar>();
public void put( String s, Bar b ) {
synchronized( myMap ) {
myMap.put( s,b );
}
}
public void hasKey( String s, ) {
synchronized( myMap ) {
myMap.hasKey( s );
}
}
public void add( Foo f ) {
synchronized( myList ) {
myList.add( f );
}
}
public Thing getMedianFoo() {
Foo med = null;
synchronized( myList ) {
Collections.sort(myList);
med = myList.get(myList.size()/2);
}
return med;
}
so i cant understand why and how can be a list be a lock. i always use "this" for accessing a synchronized statement. i appreciated if you can help me and thanks anyway : )
|
|
|
|
|
You can lock any object. In principal, the lock object can only be accessed by the thread that took the lock.
If you are accessing an object that is not thread safe, that can be called from multiple threads, then you should always lock that object.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
the list used as a lock is an instance of class ArrayList.
According to specification ArrayList implementation, an Arraylist is not synchroized, ie if multiple threads start accessing and or modifying the arraylist the state(data) of arraylist may get corrupted.
So the instance "list" is used as lock so that block of code is synchronized and only one thread can access the list at any given point of time.
do rate the answer or correct me if i am wrong.
thanx
Shreyas Rane
|
|
|
|
|
hi,
I have a database which has 2 tables, Employees and Foods
I want to show their data in a jTable, since i'm new to JAVA, I used binding. (Table Content -> Bound -> import Data From ...)
it works fine and perfect for Employees, but when i try to do the same to Foods it gives me a long long error, I'll just copy a few lines of error at the end. so if any one knows where is my problem please tell me
Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: No Persistence provider for EntityManager named MainRestaurantDBPU: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory:
oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException
Local Exception Stack:
Exception [TOPLINK-30005] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@16bd4dc2
Internal Exception: javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
Exception Description: predeploy for PersistenceUnit [MainRestaurantDBPU] failed.
Internal Exception: Exception [TOPLINK-30007] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while loading class: rest.Food_1 to check whether it implements @Entity, @Embeddable, or @MappedSuperclass.
Internal Exception: java.lang.ClassNotFoundException: rest.Food_1
|
|
|
|
|
I have a system include : apache tomcat webserver, a JSP/Servlet website, a local network (LAN).
I want to check user's connection to my webiste by using java code.
Please to help me !. Thanks so much.
|
|
|
|
|
Where "check user's connection" means what exactly?
In the basic sense it doesn't mean anything because your server can't run code on behalf of a user unless the user is connected. So by definition it is meaningless.
|
|
|
|
|
import java.sql.*;
import java.io.*;
import java.util.Date;
import java.util.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Aproject extends HttpServlet{
Connection con;
PrintWriter out;
ResultSet rs;
Statement st;
String s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14;
String service,service1,service_addp,service_delp,service_upp;
int cv;
public void init()
{
con=null;out=null;rs=null;
}
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
out=res.getWriter();
res.setContentType("text/html");
service=req.getParameter("ic_searchpname");
service1=req.getParameter("ic_searchpid");
service_addp=req.getParameter("ic_Addu");
service_delp=req.getParameter("ic_deleteu");
service_upp=req.getParameter("ic_Updateu");
try
{
if(service!=service1)
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:pro");
PreparedStatement pst;
String qry="select projectname,projectid,projectleader,client from project";
pst=con.prepareStatement(qry);
s1=req.getParameter("ic_newpname");
s7=req.getParameter("ic_pid"); //project name--string
s6="f";
rs=pst.executeQuery();
while(rs.next())
{
s2=rs.getString("projectname");
s3=rs.getString("projectid");
s4=rs.getString("projectleader");
s5=rs.getString("client");
if(s1.equals(s2))
{
s6="t";
res.sendRedirect("Aproject.html?ic_newpname="+s2+"&ic_pid="+s3+"&ic_pleadername="+s4+"&ic_clientname="+s5+"#top");
}else if(s7.equals(s3))
{
s6="t";
res.sendRedirect("Aproject.html?ic_newpname="+s2+"&ic_pid="+s3+"&ic_pleadername="+s4+"&ic_clientname="+s5+"#top");
}
}
if(!s6.equalsIgnoreCase("t"))
{
res.sendRedirect("Aproject.html?ic_msg=given_project_not_available");
}
pst.close();
}
else if(service_upp.equalsIgnoreCase("Modify Project"))
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:pro");
st=con.createStatement();
s8=req.getParameter("ic_newpname");
s9=req.getParameter("ic_pid");
s10=req.getParameter("ic_pleadername");
s11=req.getParameter("ic_clientname");
st.executeUpdate("update project set projectname='"+s8+"',projectid='"+s9+"',projectleader='"+s10+"',client='"+s11+"'where projectid='"+s3+"'");
res.sendRedirect("Aproject.html?ic_msg=given_details_updated");
st.close();
}
//hi....here my Delteing format is not working...i tried many methods to delete date from ms access database...but while running prg it prouce "java.lang.NullPointerException" error onl...pls say right coding to delete.............................
else if(service_delp.equalsIgnoreCase("Remove Project")){
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:pro");
///st=con.createStatement();
PreparedStatement pst;
String sql="DELETE *FROM project Where projectid=?";
pst=con.prepareStatement(sql);
//s12=req.getParameter("ic_newpname");
s13=req.getParameter("ic_pid");
//pst.setString(1, s12);
pst.setString(1, s13);
pst.executeUpdate();
//st.executeUpdate("DELETE FROM project WHERE projectid="+s13);
res.sendRedirect("Aproject.html?ic_msg=selected_project_deleted");
}
//HEre also while adding new data it producess "java.lang.NullPointerException " error....i nned help...sortly...
else if(service_addp.equalsIgnoreCase("Add New Project"))
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:pro");
PreparedStatement pst;
pst=con.prepareStatement("INSERT INTO project"+"(projectname,projectid,projectleader,client)"+"VALUES(?,?,?,?)");
s2=rs.getString("projectname");
s3=rs.getString("projectid");
s4=rs.getString("projectleader");
s5=rs.getString("client");
pst.setString(2, s2);
pst.setString(3, s3);
pst.setString(4, s4);
pst.setString(5, s5);
pst.executeUpdate();
res.sendRedirect("Aproject.html?ic_msg=selected_project_deleted");
pst.close();
}
else
{
res.sendRedirect("Aproject.html");
}
} catch(Exception e)
{
out.println(e.toString());
}
}
public void destroy()
{
try
{
con.close();
out.close();
rs.close();
}
catch(Exception e)
{
System.out.println("Unable to close connection:"+e);
}
}
}
|
|
|
|
|
Use code tags when you post code.
The exception stack trace tells you EXACTLY what line the error occurs on. That information is useful and there for a reason.
Following code is obviously wrong. The index doesn't start on 2. No idea if this is your problem or not.
pst=con.prepareStatement("INSERT INTO project"+"(projectname,projectid,projectleader,client)"+"VALUES(?,?,?,?)");
...
pst.setString(2, s2);
pst.setString(3, s3);
pst.setString(4, s4);
pst.setString(5, s5);
|
|
|
|
|
Hi, I'd like to make a program that talking(reply) to user
example
User: How do you do!
Computer : How do you do!
User: I'm tired
Computer : Have a rest !
& soon ,,,,,, thanks
|
|
|
|
|
Do not crosspost! You posted the same question in the C#-forum.
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
btw, this is one exercice from one book and I'm starting on Java classes next week. so it IS from the school book but I don't got the patience to wait, already on chapter 7 =)
I got this array
int[] waste = {6,4,0,4,3,8,4,4,6,8};
the task is to make one function find the lowest value an how many if them to the output.
now I've been thinking on something like this
public int getLowWaste() {
int maksDager = 0;
int sum = 0;
for(int i=0; i<waste.length; i++) {
if(waste[i]<waste) {
maksDager = waste[i];
sum++;
}
}
return maksDager;
}
now I think this should work to get the lowest value of the array, but not how many of them.. I'm thinking that it will see 6, mark it as the lowest, go to next value and if it's lower, mark it as lowest and so on. but when the values are changed, how so I reset the counter ?
|
|
|
|
|