 |
 |
Index ‹ java-programmer
|
- Previous
- 2
- too long filename? ? ?Hi
If i do the following, it will throw exception because the filename
is too long. How to fix it? I am using JBuilder X, JDK 1.4.2 and
windows XP.
try{
FileOutputStream f = new
FileOutputStream("projects\\os\\2004_03_04_JBuilderX\\2004_03_04_extras\\2004_03_04_BorlandXML\\2004_03_04_doc\\2004_03_04_api-doc\\2004_03_04_com\\2004_03_04_borland\\2004_03_04_xml\\2004_03_04_service\\2004_03_04_simpledb\\2004_03_04_jxinfo\\2004_03_04_ColumnName.html");
}catch (Exception ee){
ee.printStackTrace();
}
All the sub directory is exsit!!!
thanks
from Peter (email***@***.com)
- 5
- Import Map.class wrong version errorHi There....
I'm running into these import problems....
I'm trying to import the java.util.Map and java.util.HashMap Class on a
IBM AIX server running java 1.4.2.
Could anyone please help me in identifying what is that I am doing
wrong....
I have core.jar that has these files in the Lib dir...but still I get
the error...notably it says it is Wrong version 48 expecting 45....
I have no idea of this error could b....
Appreciate your response
/u/sharadch> $CLASSPATH
ksh:
/usr/java14/jre/lib/core.jar:/adw/adwinsp1/sqllib/java/db2java.zip:/adw/adwinsp1/sqllib/java/db2jcc.jar:/adw/adwinsp1/sqllib/java/sqlj.zip:/adw/adwinsp1/sqllib/function:/adw/adwinsp1/sqllib/java/db2jcc_license_cisuz.jar:/adw/adwinsp1/sqllib/java/db2jcc_license_cu.jar:.:
not found.
/u/sharadch> $PATH
ksh:
/usr/java14/jre/bin:/opt/oracle/product/9.2.0/bin:/usr/bin:/usr/ucb:/etc:/usr/dt/bin:/usr/bin:/usr/ucb:/etc:/usr/dt/bin:/usr/bin:/usr/ucb:/etc:/usr/dt/bin:/usr/bin:/usr/ucb:/etc:/usr/dt/bin:/usr/bin:/usr/ucb:/etc:/usr/dt/bin:/opt/openlink5/bin:/opt/openlink5/samples/ODBC:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java130/jre/bin:/usr/java130/bin:/usr/local/bin:/u/sharadch/bin:/opt/sas:/usr/local/bin:/opt/ks/bin:/opt/openlink5/bin:/opt/datamart/utilities:/usr/atria/bin:/adw/adwinsp1/sqllib/bin:/adw/adwinsp1/sqllib/adm:/adw/adwinsp1/sqllib/misc:/usr/bin:/etc:/usr/sbin:/usr/ucb:/u/sharadch/bin:/usr/bin/X11:/sbin:
not found.
/u/sharadch> cat HelloWorld.java
import java.util.Map;
import java.util.HashMap;
class HelloWorld {
public static void main(String args[]) {
System.out.print("Java Works !!!! ");
}
}/u/sharadch> javac HelloWorld.java
error: Invalid class file format:
/usr/java14/jre/lib/core.jar(java/util/Map.class), wrong version: 48,
expected 45
HelloWorld.java:1: Class java.util.Map not found in import.
import java.util.Map;
^
error: Invalid class file format:
/usr/java14/jre/lib/core.jar(java/util/HashMap.class), wrong version:
48, expected 45
HelloWorld.java:2: Class java.util.HashMap not found in import.
import java.util.HashMap;
^
error: Invalid class file format:
/usr/java14/jre/lib/core.jar(java/lang/Object.class), wrong version:
48, expected 45
HelloWorld.java:4: Superclass java.lang.Object of class HelloWorld not
found.
class HelloWorld {
^
6 errors
- 5
- grabbing text from non-edit java windowHow do I get the text (in a java program) from a java window that is not an
edit window (ie, cannot hilight the text with a mouse)? ie, is there
something similar to in functionality to Windows API GetWindowText()?
- 5
- Accessing the name of the CLASS/JAR file invokedHello,
I am trying to pack all my files into a JAR - this includes CLASS
files and other textual files such as help, std configs, etc.
I would like to be able to extract them from the Java app straight out
of the JAR - and for this I need to know what the name of the JAR file
invoked was (it might have been renamed for X reasons)
Is there any sure way to do this? (the alternative is to have an
external file to contain said data, but I want to know if a way to
have everything self-contained exists, first)
Thanks,
Andrew
- 5
- To smooth the movements of the mouseOn 19 jul, 07:45, Miss Elaine Eos <email***@***.com>
wrote:
> In article <email***@***.com>,
>
> email***@***.com wrote:
> > In my program, when I want to rotate or translate, movements abrupt.
> > How would you smooth the movements of the mouse?
>
> Abrupt in what way? Is it jerky? Smooth but too fast? Not able to do
> small movements?
>
> --
> Please take off your pants or I won't read your e-mail.
> I will not, no matter how "good" the deal, patronise any business which sends
> unsolicited commercial e-mail or that advertises in discussion newsgroups.
? ummm...It seems that you are dangerous...jijiji
Well, well. Movements, like the rotation, are too fast.If I move a
little the mouse, the scene is moved very fast.
I Can I make it slower?
(Sorry for my writing. I'm not english, and I'm beginning with the
English...^_^ )
Thanks
- 5
- Graphics2D to ImageIcon problemI'm trying to do something that should be very simple.
I want to create an applet (or application, doesn't matter) to display a set
of drawn objects (drawn with a Graphics2D object). I want to be able to display
these objects in a pane by choosing them from a combo box. Two panes, one
on top with the combo box, one on the botton with the graphic.
I managed to get the images to be drawn in a simple panel stacked next to
each other but I really want to be able to select them and have them drawn
one at a time when selected in the combo box.
My program currently just instantiatest my classes that do the Graphics2D
drawing (the classes extend JPanel and just have a paint method in them)
and puts them in a grid layout.
REAL QUESTION: I would like to create an ImageIcon and just update it
with a new image when the combo box selection changes.
The problem is I can't seem to find a way to convert a
BufferedImage or a Graphics2D object into an ImageIcon.
Should I be doing this in a different way?
I don't work with JAVA everyday (though I love the language) and GUI and
graphics things just frustrate me to no end. I still haven't got the right
model in my head.
Any help would be very apprciated. Thanks,
James Kimble
--------------------------------------------------------------------------
Here's the code I have at the minute:
Main calling class:
//v 1.3
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.util.*;
import java.math.*;
import javax.swing.*;
import java.net.URL;
public class DSP1 implements ActionListener
{
final static int NUM_IMAGES = 8;
final static int START_INDEX = 3;
JLabel waveLabel = null;
JPanel mainPanel, noisePanel, sinePanel, noisesinePanel, stonPanel;
JPanel selectPanel, displayPanel, wavePanel;
JComboBox rateChoices = null;
JComboBox freqChoices = null;
JComboBox waveOption = null;
// Constructor
public DSP1()
{
// Create the main panel to contain the two sub panels.
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(2,1,5,5));
mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
selectPanel = new JPanel();
displayPanel = new JPanel();
waveLabel = new JLabel();
waveLabel.setHorizontalAlignment(JLabel.CENTER);
waveLabel.setVerticalAlignment(JLabel.CENTER);
waveLabel.setVerticalTextPosition(JLabel.CENTER);
waveLabel.setHorizontalTextPosition(JLabel.CENTER);
waveLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(),
BorderFactory.createEmptyBorder(5,5,5,5)));
waveLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(0,0,10,0),
waveLabel.getBorder()));
waveLabel.setText("");
String[] Wave = { "Sine", "Noise", "Sine + Noise", "Signal/Noise" };
waveOption = new JComboBox( Wave );
waveOption.setSelectedIndex ( 1 );
// Add border around the select panel.
selectPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Select Phase"),
BorderFactory.createEmptyBorder(5,5,5,5)));
// Add border around the display panel.
displayPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Display Phase"),
BorderFactory.createEmptyBorder(5,5,5,5)));
selectPanel.add(waveOption);
displayPanel.add(waveLabel);
mainPanel.add ( selectPanel );
mainPanel.add ( displayPanel );
waveOption.addActionListener(this);
}
// Implementation of ActionListener interface.
public void actionPerformed(ActionEvent event)
{
if ( "comboBoxChanged".equals(event.getActionCommand()) )
{
System.out.println ( "In action: " +
waveOption.getSelectedIndex() );
switch ( waveOption.getSelectedIndex() )
{
case 0: wavePanel = new SineWave();
displayPanel.add(wavePanel);
break;
case 1: wavePanel = new NoiseWave();
mainPanel.add(wavePanel);
break;
case 2: wavePanel = new NoiseSineWave();
mainPanel.add(wavePanel);
break;
case 3: wavePanel = new SignaltoNoise();
mainPanel.add(wavePanel);
break;
}
}
}
// main method
public static void main(String[] args)
{
// create a new instance of DSP1
DSP1 dsp_1 = new DSP1();
// Create a frame and container for the panels.
JFrame dsp1Frame = new JFrame("Lunar Phases");
// Set the look and feel.
try
{
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch(Exception e) {}
dsp1Frame.setContentPane(dsp_1.mainPanel);
dsp1Frame.setBounds(300,300,500,500);
// Exit when the window is closed.
dsp1Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Show the converter.
//dsp1Frame.pack();
dsp1Frame.setVisible(true);
}
}
Drawing class (they're all the same format):
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.event.*;
import java.util.*;
import java.math.*;
import javax.swing.*;
import java.net.URL;
class SineWave extends JPanel
{
static int rate;
public void paint (Graphics g)
{
Graphics2D g2D; // Get a Java 2D device context
super.paint(g);
g2D = (Graphics2D)g; // Get a Java 2D device context
g2D.drawString("Sine Wave", 250, 10); // Draw some text
g2D.drawString(" 100", 15, 95 ); // Draw some text
g2D.drawString(" 0", 15, 205); // Draw some text
g2D.drawString("-100", 15, 305); // Draw some text
g2D.drawLine ( 40, 200, 460, 200 );
int old_x = 50;
int old_y = 200;
int new_x = 50;
int new_y = 200;
for ( int i=1; i <= 100; i++ )
{
old_x = new_x;
old_y = new_y;
new_x += 4;
new_y = (int)(((Math.sin((6.2830/100.0)*i))*100)+200.0);
//System.out.println ( "From: " + old_x + ", " + old_y +
// " To: " + new_x + ", " + new_y );
g2D.drawLine ( old_x, old_y, new_x, new_y );
}
}
public static void setRate ( int r )
{
rate = r;
}
}
- 5
- has anyone gotten this exception using SkinLF?I get the following exception when loading certain skins with SkinLF
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at
com.l2fprod.gui.plaf.skin.impl.gtk.GtkSeparator.getPreferredSize(GtkSeparator.java:92)
at
com.l2fprod.gui.plaf.skin.CompoundSkin$CompoundSeparator.getPreferredSize(CompoundSkin.java:961)
at
com.l2fprod.gui.plaf.skin.SkinSeparatorUI.getPreferredSize(SkinSeparatorUI.java:84)
It only happens when i try and load certain dialogs, and I'm not sure
which dialogs it happens it. I can try and come up with a small example
if no one has seen this before. (An example of a skin this occurs with
is: b0sumiErgothemepack.zip)
thanks!
- 7
- Date ArithmeticArg,
So I know I use the Calendar abstract class. And I am betting that I use
the Add method.
Could I see a example of some date arithmetic, e.g. number of days from
today since 01/01/1964.
Must I work out the differences by year, month, day individually, convert to
a common unit of time, add them, then convert to a displayable unit of time?
Struggling...
- 8
- DSHOW filter graph displayed in a java object??I am getting ready to start looking at integrating a standalone DSHOW viewer
into a java2 applet that we use for control. I know that using JMF, you can
do a media player but I simply want a window that display the DSHOW output
as part of the applet running in IE under WinXP. I currently have a static
JPEG view but want to modify for motion video.
Thanks for any ideas.
Doug George
- 9
- System clock monitoringwe have a java applet game that relies on a thread that ticks at 10n
miliseconds. Our problem is that we use the system clock time to see
the interval of ticks, and if a user manipulates the clock setting,
then we get erronous tick times.
Is there a way we can avoid this, or use the hardware clock , or some
solution where the user inteferenece will not disrupt the game ?
Thanks for all your suggestions,
-Vidhi.
- 11
- BPEL Products(Business prcess execution Language 4 webservices)Hi,
I had a few questions about BPEL products
1) Can you let me know the BPEL Servers available in the market. Do
these need to be integrated with J2EE appservers or can they run as is
if all I want to do is integrate a few Java applications and
webservices to the flow.
2) How powerful are Weblogic Integration suite and Websphere MQSeries
Integrator for integrating Webservices using BPEL. Also how easy is it
to develop this kind of flow. Collaxa has a more pure BPEL product
that seems easier for the above task.
Thanks in Advance,
Regards,
Rahul
- 11
- [Struts] ActionForm not displayed"Hamvil" <email***@***.com> wrote in message
news:email***@***.com...
> Basically i would like to fill a form with the data obtained from a
> database. Here follow a small part of the code:
>
> try {
> actionForm = registerManager.loadProfile(id);
> } catch (Exception e) {}
>
> basically actionForm is the one passed by the execute mathod.
>
> The method loadProfile returns an object RegisterBean (which extends
> ActionForm) that contain the user data loaded from the database.
I don't think you're supposed to construct your own form-- there's more to
it than the data. If you look at the API, you'll see some other attributes
that your own form is probably missing.
http://struts.apache.org/api/org/apache/struts/action/ActionForm.html
There is a way to ask the framework to make you a new form bean, but in this
case you don't really need that.
Instead of trying to replace the form bean with your own, try copying all of
the matching properties into it with:
BeanUtils.copyProperties( form, objectFromDatabase );
The Struts example webapp has an example of prepopulating a form. Using
forms as Data Transport Objects is generally frowned upon as it
unnecessarily couples your data access layer to Struts.
--
Wendy
- 11
- a cuestionHello
Which is the utility of declaring a interface without methods in Java?
thanks
- 11
- imcompatible type when converting a List to arrayI have an ArrayList<Guest> which I want to convert to an Array, but I'm
getting:
init:
deps-jar:
Compiling 2 source files to /home/thufir/JavaProject28/build/classes
/home/thufir/bcit-comp2611-project2/src/a00720398/view/Tabs.java:15:
incompatible types
found : java.lang.Object[]
required: a00720398.data.Guest[]
Guest some_guests[] = FileUtil.getGuests().toArray();
1 error
BUILD FAILED (total time: 6 seconds)
If I change it to:
Object some_guests[] = FileUtil.getGuests().toArray();
then it works fine, but that's rather absurd because I know that the type
is Guest so I don't see why it would have to be an array of Object.
Surely I don't have to cast to Guest?
thanks,
Thufir
- 11
- String ExternalizationI know, generally, hard coding strings is not the best thing in the
world to do. However, if I am not planning on changing those strings
(especially if the application has already been written - and it's
big), is there any reason to incur the overhead (time to implement,
overhead of the use of Properties, etc) to convert an application so
it uses a .properties file.
Just curious what other developer opinions are.
Thanks.
|
| Author |
Message |
Debaser

|
Posted: 2004-11-12 2:00:00 |
Top |
java-programmer, Newbie Question: Layouts
I've been having the toughest time with this....
I want to have a JFrame with 3 containers in it.
The containers are laid out top to bottom.
Inside the first 2 containers I want 4 rows of a JLabel and
JTextField. Components are lined up in both containers so that the
labels end and textfields start at the same place on each line. These
two containers also have a titled borders, as does the third container
which is just a JTextArea. My questions are: what type should these
containers be? what type of layout should I use for them (and what
should the parameters to the method be if any)?
Thanks.
|
| |
|
| |
 |
Andrew Thompson

|
Posted: 2004-11-12 2:11:00 |
Top |
java-programmer >> Newbie Question: Layouts
On Thu, 11 Nov 2004 12:59:34 -0500, Debaser wrote:
> I've been having the toughest time with this....
> I want to have a JFrame with 3 containers in it.
> The containers are laid out top to bottom.
> Inside the first 2 containers I want 4 rows of a JLabel and
> JTextField. Components are lined up in both containers so that the
> labels end and textfields start at the same place on each line. These
> two containers also have a titled borders, as does the third container
> which is just a JTextArea. My questions are: what type should these
> containers be? what type of layout should I use for them (and what
> should the parameters to the method be if any)?
One way to achieve the basic effect you are after is
a nested layout. The outermost layout would be a
BorderLayout, that would contain your JTextArea in SOUTH.
The top two areas would be in JPanels with another layout
in the main NORTH and CENTER areas. Each JPanel would have
a layout and/or other panels to further divide it. As best I
understand your description, a further BorderLayout with the
JLabels in a GridLayout in WEST, while the JTextFields are in
a GridLayout in EAST.
For more ideas, see the Java Tutorial on lyout managers..
<http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html>
HTH
--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
|
| |
|
| |
 |
Fahd Shariff

|
Posted: 2004-11-12 2:17:00 |
Top |
java-programmer >> Newbie Question: Layouts
Use a gridlayout (at the root) with 3 rows and 1 column. To this add
your three containers.
The first two containers could have another grid layout with 4 rows and
2 columns each. To this simply add your jlabel, textfield pair. The
third container would have a BorderLayout to which you add a JTextArea
in the center. To each container, borders can be added.
The containers could just be JPanels with the layouts set as explained
above.
JPanel rootP = new JPanel() ;
rootP.setLayout(new GridLayout(0,1));
//now build the 3 containers:
JPanel c1 = new JPanel() ;
c1.setLayout(new GridLayout(0,2)) ;
c1.setBorder(.....) ;
c1.add(new JLabel("label1")) ;
c1.add(new JTextField()) ;
//and so on
//remember that the number of columns are 2 and the number of rows
increases dynamically as we add stuff
JPanel c3 = new JPanel(new BorderLayout()) ;
JScrollPane scroll = new JScrollPane(new JTextArea()) ;
c3.add(scroll,BorderLayout.CENTER) ;
rootP.add(c1) ;
rootP.add(c2) ;
rootP.add(c3) ;
//add rootP to the contentPane of the JFrame:
f.getContentPane().add(rootP) ;
The code above may have errors! I have written it on the fly, so please
try to make sense of it!
Hope this helps,
|
| |
|
| |
 |
Jaap de Bergen

|
Posted: 2004-11-12 4:43:00 |
Top |
java-programmer >> Newbie Question: Layouts
On Thu, 11 Nov 2004 12:59:34 -0500, Debaser <email***@***.com> wrote:
>I've been having the toughest time with this....
>I want to have a JFrame with 3 containers in it.
>The containers are laid out top to bottom.
>Inside the first 2 containers I want 4 rows of a JLabel and
>JTextField. Components are lined up in both containers so that the
>labels end and textfields start at the same place on each line. These
>two containers also have a titled borders, as does the third container
>which is just a JTextArea. My questions are: what type should these
>containers be? what type of layout should I use for them (and what
>should the parameters to the method be if any)?
>
I'm using formlayout from jgoodies, this layoutmanager can solve most
layout problems. It wise with formlayout to make a quick drawing on
paper so you can draw the rows and columns. After you have done that,
you can make your gui easily with formlayout. I must warn you the
definition of the rows and columns are a bit difficult to understand.
But the other day i saw that there are several (free and commercial)
gui builders which support formlayout.
For me personal i still like the old paper drawing and typing. Though
i wish i could place comments in the rows and column definitions,
because after a month of 2 it's difficult to understand without
comments.
Jaap
|
| |
|
| |
 |
A. Bolmarcich

|
Posted: 2004-11-12 7:08:00 |
Top |
java-programmer >> Newbie Question: Layouts
On 2004-11-11, Debaser <email***@***.com> wrote:
> I've been having the toughest time with this....
> I want to have a JFrame with 3 containers in it.
> The containers are laid out top to bottom.
> Inside the first 2 containers I want 4 rows of a JLabel and
> JTextField. Components are lined up in both containers so that the
> labels end and textfields start at the same place on each line.
[snip]
Trying to get the horizontal position where the labels end and
textfields start to be the same in two different containers is
going to be difficult, if that horizontal position depends on
the preferred widths of the labels or textfields. Layout
managers are usually not designed to exchange layout information
with each other.
It would be better to use
- a single container that has all the rows, or
- a container that has all the label and a separate container
that has all the textfields
It is possible to use GridBagLayout and extra code that
- invokes getLayoutDimensions on the layout managers of the two
containers to get the width that each layout manager used
for its label column
- if the widths of the label columns are not the same, sets
the columnWidths field of the GridBagLayout with the smaller
width to be the width used by the by the other GridBagLayout,
and invokes layoutContainer to layout again (so it uses the
value of columnWidths that was just set)
It would likely be a good idea to write your own layout manager
that more directly exchange layout information with another
instance of itself.
|
| |
|
| |
 |
Karsten Lentzsch

|
Posted: 2004-11-13 3:10:00 |
Top |
java-programmer >> Newbie Question: Layouts
Debaser wrote:
> [...]
> which is just a JTextArea. My questions are: what type should these
> containers be? what type of layout should I use for them (and what
> should the parameters to the method be if any)?
You can nest panels (and their layouts), or you can
implement this with a single panel and layout.
Nesting makes the implementation easy to read,
but typically you cannot align content that is
located in different panels. This is because
only very few layout managers offer inter-panel
layout constraint to align content over multiple
panels.
A frequent source for poorly aligned designs
is the TitledBorder. The Mac Aqua Style Guide
provides a chapter where you can study how to
replace the titled borders with alternatives
that often lead to better design.
I provide two presentation regarding this issue,
"First Aid for Swing" and "Advanced Layout and
Panel Building", see http://www.jgoodies.com/articles/
Best regards,
Karsten Lentzsch
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2004-11-16 8:30:00 |
Top |
java-programmer >> Newbie Question: Layouts
Andrew Thompson coughed up:
> On Thu, 11 Nov 2004 12:59:34 -0500, Debaser wrote:
>
>> I've been having the toughest time with this....
>> I want to have a JFrame with 3 containers in it.
>> The containers are laid out top to bottom.
>> Inside the first 2 containers I want 4 rows of a JLabel and
>> JTextField. Components are lined up in both containers so that the
>> labels end and textfields start at the same place on each line. These
>> two containers also have a titled borders, as does the third
>> container which is just a JTextArea. My questions are: what type
>> should these containers be? what type of layout should I use for
>> them (and what should the parameters to the method be if any)?
>
> One way to achieve the basic effect you are after is
> a nested layout. The outermost layout would be a
> BorderLayout, that would contain your JTextArea in SOUTH.
>
> The top two areas would be in JPanels with another layout
> in the main NORTH and CENTER areas. Each JPanel would have
> a layout and/or other panels to further divide it. As best I
> understand your description, a further BorderLayout with the
> JLabels in a GridLayout in WEST, while the JTextFields are in
> a GridLayout in EAST.
AFAICT, from what it seems that the OP is asking, this would not suit his
needs. This does not /guarantee/ that the labels and textfields from the
1st component line up with the labels and textfields of the 2nd.
...[rip]...
--
Everythinginlifeisrealative.Apingpongballseemssmalluntilsomeoneramsitupyourn
ose.
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Java 5 threads in linuxHi,
I am using the following java version in Linux
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)
Threads are created using the source code:
private static ExecutorService thPool =
Executors.newFixedThreadPool(5);
My question is how threads are created in linux using the mentioned
runtime.
1. Does the code line above create 5 linux native threads (process)?
2. Does it create java threads? Don't know if java and native threads
are same.
3. If answer of the question 1 is "NO" then does one native linux
threads for java runtime do all the concurrent execution?
Please explain. Any documents on java threads in Linux for java 5?
Thanks in advance
Sunny
- 2
- Overiding Static MethodsThis is a multi-part message in MIME format.
Hi,
When you override a non-static method, a call to that method from the super-class properly results in the sub-class version of that method being called. BUT, when you override a static method, it appears --to my frustration-- that a call to that method from the super-class results in the super-class version of the method being called!
Here is an example of what I mean. My intention is for the following to print out "Success" but it always prints out "Failure." instead.
It seems to ignore the fact that I have overrided method2( ) from ClassA with method2( ) from ClassB.
class ClassA
{ static void method1 () { method2(); }
static void method2 () { System.out.println("Failure."); }
}
class ClassB extends ClassA
{ public static void main (String[] args) { method1(); }
static void method2 () { System.out.println("Success."); }
}
I can get around the this problem by removing the static modifier, creating a third class, and instantiating a ClassB object. Like below. But I'd rather not have to create a third class, and instantiate an object if there is a way to to keep the code smaller,simpler,easier. Is there a way to fix the code above so that it prints "Success" instead? It just seems like there ought to be!
class ClassA
{ void method1 () { method2(); }
void method2 () { System.out.println("Failure."); }
}
class ClassB extends ClassA
{ void method2 () { System.out.println("Success."); }
}
class Start
{ public static void main (String[] args)
{ ClassB b = new ClassB();
b.Method1();
}
}
-Ken
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Hi, </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>When you override a non-static method, a call to
that method <EM>from the super-class </EM>properly results in the sub-class
version of that method being called. BUT, when you override a static
method, it appears --to my frustration-- that a call to that
method <EM>from the super-class </EM>results in the super-class version of
the method being called! </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Here is an example of what I mean. <STRONG>My
intention</STRONG> is for the following to print out "Success" but it
always prints out "Failure." instead. </FONT></DIV>
<DIV><FONT face=Arial size=2>It seems to ignore the fact that I have
overrided method2( ) from ClassA with method2( ) from ClassB.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>class ClassA <BR>{ static void
method1
() { method2(); }<BR>
static void method2
() { System.out.println("Failure.");
}<BR>}</FONT></DIV>
<DIV><FONT face=Courier size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>class ClassB extends ClassA </FONT></DIV>
<DIV><FONT face=Courier size=2>{ public static void main (String[]
args) {
method1(); }<BR> static
void method2
()
{ System.out.println("Success."); }<BR>}<BR></DIV></FONT>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I can get around the this problem by removing
the static modifier, creating a third class, and instantiating a
ClassB object. Like below. But I'd rather not have to create a third
class, and instantiate an object if there is a way to to keep the code
smaller,simpler,easier. Is there a way to fix the code above so that it
prints "Success" instead? It just seems like there ought to
be!</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>class ClassA </FONT></DIV>
<DIV><FONT face=Courier size=2>{ void method1 ()
{
method2();
}<BR> void method2 () {
System.out.println("Failure."); }<BR>}</FONT></DIV>
<DIV><FONT face=Courier></FONT> </DIV>
<DIV><FONT face=Courier size=2>class ClassB extends ClassA </FONT></DIV>
<DIV><FONT face=Courier size=2>{ void method2
() {
System.out.println("Success."); }<BR>}</FONT></DIV>
<DIV><FONT face=Courier></FONT> </DIV>
<DIV><FONT face=Arial size=2><FONT face=Courier>class Start </FONT></FONT></DIV>
<DIV><FONT face=Arial size=2><FONT face=Courier>{ public static void
main (String[] args) </FONT></FONT></DIV>
<DIV><FONT face=Arial size=2><FONT face=Courier> {
ClassB b = new ClassB();<BR>
b.Method1();<BR> }</FONT><BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>-Ken</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>
- 3
- from text file to InputSource (another how to get there from here question)I need to pick up a file sitting in WEB-INF/classes, which I usually do like
this:
ClassLoader cl = MyClassName.class.getClassLoader();
InputStream rules = cl.getResourceAsStream( XML_RULES );
But an InputStream won't do, the createDigester method takes either
org.xml.sax.InputSource or java.net.URL .
Initially, I had this:
ClassLoader cl = MyClassName.class.getClassLoader();
InputStream rules = cl.getResourceAsStream( XML_RULES );
Digester digester = DigesterLoader.createDigester( new InputSource(
rules) );
And then I got it down to:
ClassLoader cl = MyClassName.class.getClassLoader();
Digester digester = DigesterLoader.createDigester( cl.getResource(
XML_RULES ) );
(ClassLoader.getResource returns a URL.)
There's probably a more direct path, I just don't see it.
What methods other than ClassLoader.getResource and getResourceAsStream can
find things on the classpath? InputSource has a constructor that takes a
'system identifier' but I haven't been able to figure out exactly what that
is.
Thanks once again!
--
Wendy
- 4
- Usage of 'javap' to decompile into useful codeThe following is the source code contained within myClass.java
-----------------
package main.sub;
public class myClass
{
public static final boolean ISDEBUG = true;
}
-----------------
If I use javap to decompile from the corresponding .class, I get only this:
user@machine: javap main.sub.myClass
Compiled from myClass.java
public class main.sub.myClass extends java.lang.Object {
public static final boolean ISDEBUG;
public main.sub.myClass();
}
How do I have to use 'javap' to get the exact code, as shown above?
- 5
- struts radio indexed fieldGreetings to all -
I'm having some difficulty to render indexed radio input fields
correctly. The problem is that it's a "double" indexed example. The
jsp operates on the collection of the Question instances. And each
question has a list of pre-defined answers to choose from. The idea is
to list all of the questions and then collect the answers chosen. The
"list" and "text" types are working (generating both
name="questions[x].answer", where x is the index of the question) but
radio does not.
If indexed="true" is specified, then each pre-defined radio answer has
a name="questions[x].answer" WHERE x is the index of the PRE-DEFINED
ANSWER from the predefinedAnswers iterator (not from the questions
iterator).
If indexed attribute is not specified, then the input field name is
rendered just as name="answer".
There should be a way to make it work. Is nested:radio going to help
in any way ? Any suggestions are very appreciated.
Thanks
Pavel
Here is the relevant portion of the jsp:
<logic:iterate id="questions" property="questions"
name="questionSetForm">
<logic:equal name="questions" property="type" value="list">
<div>It's a list</div>
<html:select name="questions" property="answer" indexed="true">
<html:optionsCollection name="questions"
property="predefinedAnswers" value="id" label="label"/>
</html:select>
</logic:equal>
<logic:equal name="questions" property="type" value="text">
<div>It's a text</div>
<html:text name="questions" property="answer" indexed="true" />
</logic:equal>
<logic:equal name="questions" property="type" value="radio">
<div>It's a radio choice</div>
<logic:iterate id="predefinedAnswer" property="predefinedAnswers"
name="questions">
<html:radio name="questions" property="answer" value="id"
idName="predefinedAnswer">
<bean:write name="predefinedAnswer" property="label" />
</html:radio>
</logic:iterate>
</logic:equal>
</logic:iterate>
The questionSetForm class defines only one property that hold a
collection of Question instances:
public List getQuestions() {
return questions;
}
public void setQuestions(List questions) {
this.questions = questions;
}
The Question class defines the following relevant properties (along
with corresponding get/set methods):
private Integer id = null;
private Integer questionSetId = null;
private String type = null;
//Holds the collection of the PredefinedAnswer instances
private List predefinedAnswers = null;
private String label = null;
private String answer = null;
The PredefinedAnswer class defines the id and label properties used to
render the list of choices.
- 6
- Secure access to database applicationHi All
Just looking for a bit of advice. I have an muti-user application
that I'm developing that talks to an Oracle database. What's the best
way (or at least a good way!) of securing user + password access to
the program? I've currently got a user table in the database and I
fetch whether the login credentials match what's in that table - but I
log in as an admin user to the DB in order to fetch the user table, so
admin password is coded into the application - this is obviously
bad.
Ideas? I presume there's a standard way of doing these kinds of
things :o)
- 7
- DefaultTableModel Column IdentifiersWhy is it that I can set a column identifier as an Object with:
model.setColumnIdentifiers(new Object[]{myObject});
Yet if I then call:
Object x = new JTable(model).getColumnModel().getColumn(0).getIdentifier();
x is not myObject but myObject.toString()
Surely there's something screwy going on here?
In fact, is there any way I can get reference to myObject without
subclassing DefaultTableModel?
Any help appreciated!
Ant
Using Using jdk1.3.1_02, code snippet below:
**************************************
Object myObject = new Double(4.2);
DefaultTableModel model = new DefaultTableModel();
model.setColumnIdentifiers(new Object[]{myObject});
Object x = new JTable(model).getColumnModel().getColumn(0).getIdentifier();
System.out.println("myObject is a "+myObject.getClass().getName());
System.out.println("x is a "+x.getClass().getName());
**************************************
- 8
- tricky+frustrating: changing mouse handler while mouse pressed doesn't workHello,
I have a quite tricky problem, on that I work on for 3 days now without
success. It's frustrating. *sigh* :-(
I am using Piccolo, a zoomable UI framework
<http://www.cs.umd.edu/hcil/jazz/download/>, to create a 2D space on which
I can place different kinds of nodes, e.g., pictures. However, my problem
is more general and not Piccolo based.
Every node on this 2D space has its own mouse event handler attached. With
the mouse event handler you can click on a node and drag it to another
place.
Every node has internally its unique index ID. If two nodes intersect, then
the one with a higher index is displayed above a node with lower index.
Currently, you can drag a node anywhere, even underneath another node with
higher index.
WHAT I WANT:
Whenever a node of higher index comes between the dragged node and the
cursor, I want to release the original node and apply all mouse events to
the higher placed node.
If a user would do this manually, he/she would release the mouse button and
click again. However, the user is not doing this, but the machine should;
the user constantly just holds the mouse button pressed.
This turns out to be very difficult to handle, because the user does *not*
release the mouse button. The input handler of the node directly underneath
the cursor (that *should* handle the mouse events then), does not get
activated. :-(
Any expert here who can see how to solve this problem?
Here is the code. Don't worry about the Piccolo stuff. I think it is a
general Java question about mouse events and robots (I use java.awt.Robot
-- is this the right approach?). I have marked the problematic part:
******** <code> *******
public void mouseDragged(PInputEvent aEvent) {
// This tells other handlers that this event is now already handled now
aEvent.setHandled(true);
// Find the cursor position and the node position.
Point2D cursorPos = aEvent.getPosition();
PBounds nodePosition = aEvent.getPickedNode().getGlobalFullBounds();
// Check if the cursor is within the node's bounds. This is
// just for cases when the dragged node is slower than the cursor.
if (nodePosition.contains(cursorPos.getX(), cursorPos.getY()) {
// This retrieves the node directly underneath the cursor
PNode nodeUnderneathCursor = aEvent.getPickedNode().getRoot()
.getDefaultInputManager().getMouseOver()
.getPickedNode();
// If there is a node underneath the cursor + its not the background
if (! nodeUnderneathCursor.equals(aEvent.getPickedNode())
&& ! nodeUnderneathCursor.getClass().equals(PCamera.class)) {
// HERE IS THE PROBLEMATIC PART!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<
// Have in mind that there constantly comes a mouseDragged event
// in from the user's pressed mouse button!
try {
Robot robot = new Robot();
// this should release the mouse button for the original node
robot.mouseRelease(InputEvent.BUTTON1_MASK);
// Tell other handlers that this one doesn't want to handle anymore
aEvent.setHandled(false);
// this should perform a click; the position is right on the node
// that is between the cursor and the original dragged node
robot.mousePress(InputEvent.BUTTON1_MASK);
} catch (AWTException e) {
e.printStackTrace();
}
}
}
// Move the node to the new cursor position
Dimension2D delta = aEvent.getDeltaRelativeTo(aEvent.getPickedNode());
aEvent.getPickedNode().translate(delta.getWidth(), delta.getHeight());
}
******* </code> *******
Thanks a lot for any hint!
Claus
- 9
- gridbaglayout weightsIf I have this layout with 3 columns:
[comp1 weight=0][comp2 weight=3][comp3 weight=2]
[comp4 weight=1 gridwidth=3 ]
[comp5 weight=0.75 gridwidth=2 ][comp6 weight=4]
What would be the effective weight of each column?
Docs say the max in each so would that be:
col1 - 1
col2 - 3
col3 - 4
and what would be the effect of the weights on comp4 and comp5 when resizing
as they span cols with different weights?
Cheers, Richard.
- 10
- Passing a method(reference) to an other method and calling the method.On Fri, 28 Mar 2008 02:58:17 -0700 (PDT), Erik <email***@***.com>
wrote, quoted or indirectly quoted someone who said :
>I have a staight forward question. Is is posible to pass a method as a
>parameter and call the passed
>method from within the other method?
see http://mindprod.com/jgloss/callback.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
- 11
- JTable Editing not take effect until hit EnterHello dudes,
I found out if you editing a JTable cell without hit
the Enter or Tab key. Then the new cell value won't take
effect. For example, a table cell value is "abc" and
you change it to "xyz". Then when you read that table
cell value, it still "abc". You MUST hit the Enter or
Tab key, then you will get that table cell value as "xyz".
How can I force that table cell value as "xyz" WITHOUT
hit the Enter or Tab key?
Thank Q very much in advance!
- 12
- inputting local filepathI am attempting to input a database location from a txt file located
within the build folder. However, I am having a bitchin time getting
it to work with relative file location. So far, I can only get
absolute file names to work, this is useless. Any help would be
appreciated. My code can be found below....
import java.sql.*;
import javax.swing.DefaultListModel;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class DataConnection {
public DataConnection(){
DataInputStream input;
String name = "";
File dBLocation = new File("C:\\Documents and
Settings\\Owner.JustinLaptop\\Desktop\\USC
Programs\\ConsultRequest\\build\\classes\\consultrequest\\testing\\dBURL.txt");
dBLocation = new File("..consultrequest\\testing\\dBURL.txt");
System.out.println(dBLocation.getParentFile());
System.out.println(dBLocation.exists());
try { // try to create an object representing the user-selected file
input = new DataInputStream( new FileInputStream(dBLocation) );
try { // try to read the file and create a string consisting of
its contents
char ch;
do { // read data from the file until end of file is reached
name = "";
ch = input.readChar();
while ( ch != ';' ) {
name = name + ch;
ch = input.readChar();
}
}
while ( true );
} catch ( Exception ex ) {
}
try { // try to close the file
input.close();
} catch ( Exception ex ) {
}
} catch ( Exception ex ) {
System.out.println("Database location cannot be found");
}
System.out.println(name);
}
public static void main(String[] args){
DataConnection data = new DataConnection();
}
}
- 13
- Question About Scaling Virtual World to Real World..Hello,
i m developing one Java3D application, which takes real world
coordinates from database, e.g. (330020,22030 , its in MM(milimeter)).
So i have to place objects in My virtual world. but SimpleUniverse can
view upto 10 Meters ( i dont know How to extend this limit, if you
know then please tell me)... so i have to define Virtual Universe. And
actually i didnt got any simple code, which explain virtual universe
in Detail. So i need simple code which use Virtual Universe. or link.
Waiting for reply.
- 14
- Struts Eclipse JSTLHi,
I am an eclipse newbie. I need a free ide to develop struts with jstl.
I was wondering if anyone knew how to setup eclipse 3.2.1 with struts.
I was wonderng if any one could help me out. I cant seem to find any
good non commercial plugins for eclipse to do this
Thanks
:)
- 15
- creating an ESRI shapefileI need to create an ESRI shapefile set (.shp, .shx, .dbf) from an
object. The object is drawn to the screen -- or any Graphics2D -- via
its draw() method, so a good starting point would be an implementation
of Graphics2D which writes to a shapefile instead of the screen.
Does anybody know of a good library to help with the creation of
shapefiles in Java?
|
|
|