 |
 |
Index ‹ java-programmer
|
- Previous
- 5
- 7
- GUI Object DesignI am pretty new to Java and I am trying to get my hands around OOD.
In the course of designing a GUI, I am working on breaking down the
components into the necessary objects so that the code will be as
versatile as possible.
As I work through it though, I am confronted with the situation where
I feel that I am over analyzing and creating too many objects.
Let's say that I have a pretty basic window application. It has a
window with a menu bar and three menus, each with a few items.
The main window is an object inherited from JFrame.
Is it best to make the menu a seperate object, inherited from
JMenuBar, and then make each menu a seperate object, inherited from
JMenu, and then make each menu item a seperate object, inherited from
JMenuItem? Or, is a lot of this typically placed within a single,
larger object?
I guess I am wondering where you draw the line. How do I know when I
have gone too far and am creating too many objects unnecessarily?
I imagine a lot of this dicussion is personal preference and some
aspects are open to debate. I am just looking for some guidance as I
learn more about this.
Thanks.
- 8
- Suspending threads by ThreadPoolExecutorHi all,
Does ThreadPoolExecutor may suspend idle threads ?
I wonder wether suspended threads eat less resources than active ?
I imagine the solution when ThreadPoolExecutore suspends each idle
threat after idleness of 60 seconds and after next 60 seconds of being
suspend the thread got killed ?
Is it reasonable ?
Regards,
Maciej
- 8
- 10
- Array iteration question/*Can i calculate the page totals, column totals, and rowtotals in one pass
through the array instead of the three passes i have coded? I have already
added an outer for loop to combine the three seperate iterations into one
but it still loops through the array multiple times and i would like to have
it loop through only once*/
import java.io.*;
import java.util.*;
import java.text.NumberFormat;
class P3
{
static PrintWriter screen = new PrintWriter (System.out,true);
public static void main (String [] args) throws IOException
{
final int COLLEGES = 4;
final int GENDERS = 2;
final int LANGS = 4;
int langAccum, genderAccum, collegeAccum, totalAccum = 0;
float percentage;
StringTokenizer data;
File file = new File ("p3input.txt");
FileReader inputFile = new FileReader (file);
BufferedReader inFile = new BufferedReader(inputFile);
String [] languageNames = {"C++" , "Cobol" , "Java" , "VB"};
String [] collegeNames = {"CCSU", "ECSU", "SCSU", "WCSU"};
String [] genderNames = {"Male", "Female"};
int [][][] enrollment = new int[COLLEGES][GENDERS][LANGS];
NumberFormat percent = NumberFormat.getPercentInstance();
// load array with values from file
for (int college = 0; college < COLLEGES; college++)
{
data = new StringTokenizer (inFile.readLine());
for (int gender = 0; gender < GENDERS; gender++)
for (int lang = 0; lang < LANGS; lang++)
{
enrollment[college][gender][lang] = new Integer
(data.nextToken()).intValue();
totalAccum += enrollment[college][gender][lang];
}
}
screen.println ("\nStudent Enrollment Survey Results:\n");
// first iteration to calculate percentage by language
screen.println ("Language\tPercentage");
for (int lang = 0; lang < LANGS; lang++)
{
langAccum = 0;
for (int college = 0; college < COLLEGES; college++)
for (int gender = 0; gender < GENDERS; gender++)
langAccum += enrollment [college][gender][lang];
percentage = (float) langAccum / totalAccum;
screen.println(languageNames[lang] + "\t\t" + percent.format(percentage));
}
screen.println("\n");
// next iteration to calculate gender percentage
screen.println("Gender\t\tPercentage");
for (int gender = 0; gender < GENDERS; gender++)
{
genderAccum = 0;
for (int college = 0; college < COLLEGES; college++)
for (int lang = 0; lang < LANGS; lang++)
genderAccum += enrollment [college][gender][lang];
percentage = (float) genderAccum / totalAccum;
screen.println(genderNames[gender] + "\t\t" + percent.format(percentage));
}
screen.println("\n");
// last iteration to calculate college percentage
screen.println("Colleges\tPercentage");
for (int college = 0; college < COLLEGES; college++)
{
collegeAccum = 0;
for (int lang = 0; lang < LANGS; lang++)
for (int gender = 0; gender < GENDERS; gender++)
collegeAccum += enrollment [college][gender][lang];
percentage = (float) collegeAccum / totalAccum;
screen.println(collegeNames[college] + "\t\t" +
percent.format(percentage));
}
inputFile.close();
}
}
- 10
- Eclipse Runtime ErrorI am running Eclipse 3.1.1. I created a project, called PizzaShop.
Inside pizza shop, I have src\ lib\ and build\classes\ folders. Inside
src\, I have a pizza folder for the pizza package. That too is mirrored
in build\classes\pizza.
When I go to debug as ->debug, Eclipse tells me:
java.lang.NoClassDefFoundError: pizza/SystemTest
Exception in thread "main"
What does that mean and how do you tell Eclipse which main to run? I
think I tell it that when it pops open the configuration menu, and I
tell it "pizza.TakeOrder" for the main class to run. But, obviously, it
cannot find the main, and there is a public main() in the TakeOrder
file.
So confused, Scott
- 12
- Runtime.getRuntime().exec causing Windows 16-bit error!Hi there,
I'm trying to do something i've done many times before without problem, even
from signed applets...
trying to run a system command from Java.
I'm doing this:
import java.io.*;
public class SysCommand{
public static void main(Stirng[] args){
try{
Process proc =
Runtime.getRuntime().exec(
new String[]{"command.com",
"/C",
"echo",
"%windir%"});
BufferedReader reader =
new BufferedReader(
new InputStreamReader(
proc.getInputStream()));
System.out.println(reader.readLine());
proc.waitFor();
proc.destroy();
}
catch(Throwable th){
th.printStackTrace();
}
}
}
I'm trying to find out where the Windows directory is (i need to copy some
DLL's into there as part of an installation process).
When i run this, Windows raises a dialog box saying:
_______________________________________________________________
|16 bit MS-DOS Subsystem
|
|
|
| C:\WINNT\system32\ntvdm.exe
|
| Error while setting up environment for the application. Click 'Close'
to terminate |
---------------------------------------------------------------------------
---------
I'm running JDK 1.4.2_02 on a Win2K box.
Any ideas?
Thanks,
Paul
- 12
- command line memory profiler toolHello,
I'm looking for a simple command line tool (no windows) to help find a
memory leak in a large amount of old java code. Need to keep the test
machine identical to the production box, which is without xwindows.
Thanks for your help,
Erik
- 12
- Problem with deploytool.I am trying to build a web service starting from hand-written wsdl using
JAX-RPC and wscompile tool from Sun Java System Application Server 8.0.
I don't want any data binding, so i invoke wscompile tool with -f
nodatabinding option with deploytool I create war, and I try to deploy it.
And deployment fails!
Reading server log I have found that reason for this failure is ejbc:
[#|2004-09-29T21:09:41.174+0200|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.stream.out|_ThreadID=11;|
error: [failed to localize] unable to find member rodzajProblemu in
jaxrpcmapping meta for exception whose wsdl message is:
{http://www.eAdministracja.gov.pl/wsdl/ZDGUsluga}problemPrzetwarzania|#]
Message refers to part of my schema cited below:
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:ug="http://www.eAdministracja.gov.pl/UrzadGminy/typy"
targetNamespace="http://www.eAdministracja.gov.pl/UrzadGminy/typy">
<complexType name="ProblemPrzetwarzania">
<sequence>
<element name="rodzajProblemu">
<simpleType>
<restriction base="string">
<enumeration value="Merytoryczny"/>
<enumeration value="Systemowy"/>
</restriction>
</simpleType>
</element>
<element name="oznaczenieProblemu" minOccurs="0" type="string"/>
<element name="opisProblemu" type="string"/>
</sequence>
</complexType>
<element name="problemPrzetwarzania" type="ug:ProblemPrzetwarzania"/>
</schema>
Identifiers are polish words, so don't bother with making up what do
they mean.
I have checked mapping.xml generated by wscompile, and ejbc is right -
there is nothing about rodzajProblemu, but if there is no class bound to
element problemPrzetwarzania except SOAPElement, there is no mapping,
so deploytool shouldn't try to compile any bean!
Should I consider it to be bug or I am doing sth. wrong?
- 14
- Focusing a JPanel?Is there a way to give a JPanel focus on a mouse click besides explicitly
saying "panel.requestFocus()"? I tried "panel.setFocusable(true)", but it
had no discernable effect. Using J2SE 1.4.2.
--
Ryan Stewart, A1C USAF
805 CSPTS/SCBE
- 15
- Export ApplicationHello.
I am using Netbeans 3.5 IDE and have created several applications which is
fine and dandy. The only thing I cannot do is work out how to export these
apps to another PC i.e. to run them on a machine without having the IDE
installed. I believe this would be via a JAR file but cannot seem to get
these to work. Any help in this area would be great as I am going round in
circles. Also, how do I encrypt the code ?
Regards
Stephen Gray
(Apologies if this is the wrong forum)
- 15
- Making Form results readableI have coded a simple form that sends the results to an email. The
form works, but when I recieve the data it is all together in one big
line. What kind of coding do I need to do to separate the data and
label it as well. Do I need to create some sort of template in
notepad??? I am a very beginner coder.
Thanks,
Lindsay
- 16
- Encryption & DecryptionHi all
I've been asked to look into the encryption and decryption of attachments
sent in emails. The specific scenario is as follows:
- a file is created
- the file is to be encrypted
- the file is attached to an email and sent to a recipient
- once received, the file should be decrypted
- the file is read
At first glance, I think I should be reading up on the JCA (Java
Cryptography Architecture) and use a public key encrypt and a private key to
decrypt. Is this right?
Are there any online implementations or tutorials that you would suggest I
read to learn more about this?
--
Rogue Chameleon...
- 16
- adjusting boundries of JPanels in JPanel in JFrameHi, I tried searching through the google groups, but am obviously using the
wrong search words.
I have a JFrame with a JPanel in it. The JPanel is using the following
layout:
new BoxLayout (parentPanel, BoxLayout.LINE_AXIS)
Then I added two JPanels to the parentPanel.
But then I would like to click and drag the separator between the two panels
to change the size of the two JPanels.
Any hints?
Thanks,
Novice
- 16
|
| Author |
Message |
nialltimpson

|
Posted: 2005-3-23 0:51:00 |
Top |
java-programmer, javakey
Hey Im in a spot of bother I have set the path in my windows xp to point to
java bin dir. and can run javac, but when ever I go to run javakey i gives
me "javakey" is not recognised as an internal or external command....
Im trying to sign some applets so they can open a network connection to
another computer. Im not 100% sure on how to do this or how difficult it
is, so any help would really be greatfully recieved.
Thanking you
niall
|
| |
|
| |
 |
Steve W. Jackson

|
Posted: 2005-3-23 2:01:00 |
Top |
java-programmer >> javakey
In article
<email***@***.com>,
"nialltimpson" <email***@***.com> wrote:
> Hey Im in a spot of bother I have set the path in my windows xp to point to
> java bin dir. and can run javac, but when ever I go to run javakey i gives
> me "javakey" is not recognised as an internal or external command....
>
> Im trying to sign some applets so they can open a network connection to
> another computer. Im not 100% sure on how to do this or how difficult it
> is, so any help would really be greatfully recieved.
>
> Thanking you
> niall
In my 1.4 JDK installation, there's no "javakey" to be found. I don't
have 1.5, but I suspect it's not there either. Are you certain you're
not really looking for things like keytool and/or jarsigner?
= Steve =
--
Steve W. Jackson
Montgomery, Alabama
|
| |
|
| |
 |
nialltimpson

|
Posted: 2005-3-23 2:38:00 |
Top |
java-programmer >> javakey
well to be hosest im not one hundred percent sure, I just have a old java
book and there's is a section on signing applets, inwhich they use
javakey. but I have never done it before and am open to ideas on how to go
about it.
|
| |
|
| |
 |
Oscar kind

|
Posted: 2005-3-23 3:26:00 |
Top |
java-programmer >> javakey
nialltimpson <email***@***.com> wrote:
> well to be hosest im not one hundred percent sure, I just have a old java
> book and there's is a section on signing applets, inwhich they use
> javakey. but I have never done it before and am open to ideas on how to go
> about it.
IIRC, javakey is from version 1.1 and has been replaced. The principle is
still the same, but the rest is different enough that you want to find a
newer tutorial/example.
--
Oscar Kind http://home.hccnet.nl/okind/
Software Developer for contact information, see website
PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Application for Nokia 3410 cell 'phone
This should be simple enough! I have a Nokia 3410. I have downloaded the
J2ME Wireless Toolkit. I would like to write some applications for the cell
'phone.
Now, I read that J2ME is a range of standards and applications, not a
platform. Fair enough.
Since this is in Java, I'd like to write my applications so that they run on
all cell 'phones - or all Nokia 'phones at least.
What I'd like to know is the following:
- What steps do I need to take to write and load a 'Hello World'application
into my 3410 and see it run?
If there is a document you can point me to, or a better newsgroup that would
be great!
Later on it would be nice to know how to advertise an cell 'phone
application so other people can download it and pay for it - but that can
wait until I have one fully written. For that I need to know the above!
--
"The pure and simple truth is rarely pure and never simple." - Oscar Wilde
- 2
- Learning ArraysHi, I am just learning arrays and I am trying to get this 2D array to print
out like this:
0 1 2 3 4 5 6
0 1 2 3 4 5 6
0 1 2 3 4 5 6
0 1 2 3 4 5 6
0 1 2 3 4 5 6
but insteads it prints out like this: 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4
5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6
I can get it to work with system.out.println but I need to use a
JOptionPane.showMessageDialog box as I have attempted to do. Any ideas?
(my code is below) Thanks!!!!!!!!!!
import javax.swing.*;
public class array5by7{
public static void main (String args[]){
String outputString = "";
int table[][] = new int [5][7];
for (int row=0; row<table.length; row++)
{
for (int col = 0; col <table[row].length; col++)
table[row][col] = 0 + col;
}
for (int row=0; row<table.length; row++)
{
for (int col = 0; col<table[row].length; col++)
outputString += (table[row][col] + " ");
}
JOptionPane.showMessageDialog (null, outputString + "\n");
}
}
- 3
- 4
- Java Applet Parameter LimitHi all,
I would like to know the maximum number of parameters that can be passed
to an applet. While I think there is no theoretical maximum, I believe
there to be a practical limitation for browsers.
I am using winXP, IE6 and firefox1, and jre1.4.2.
I have a graphing applet which works very well except when there are a
large number of parameters i.e. 5000. When I load such an example with
appletviewer the applet opens fine. However when I load the same applet
in either IE6 or firefox1 then nothing happens except the page appears
to be loading but gets no where even if you leave it for hours - in
other words the browsers seem to hang. Java does not appear to load into
memory - the icon does not appear in the system tray which leads me to
believe that it is a browser limitation, rather than a java one.
Does anyone know if there is such a limitation? Do you think it could be
remedied by merging the tags - i.e. having less but longer params? Or is
there another way of passing data to the applet?
Many thanks,
Chris.
- 5
- web browser plugin problem .... JRE not found?Hello,
I'm trying to load a Java 1.2 applet into IE 5 using the browser plugin.
When I do so, I get an error message telling me that the plugin cannot find
the JRE where in the path specified (ie., the path to which I just installed
the plugin).
What's going on here?
TIA,
- Boyd S.
- 6
- cannot call a paint function across classes?Just wondering if this is possible, as im having no luck working it out, no
matter what ive tried so far..
I have 2 classes, lets call them gP and kP. in gP ive got this function:
public void paint55(java.awt.Graphics graphics) {
Dimension d=getSize();
graphics.setColor(Color.RED);
graphics.fillRect(0, 0, (int)d.getWidth(), (int)d.getHeight());
graphics.setColor(Color.BLACK);
//call another function here
}
now, in the kP class, im using a jComboBox, the combo box works fine, but i
want to try and call that function from it
Ive tried
gP.paint55();
ive tried referencing it as gP paint55();
Just cant work it out, any ideas?
Thanks
- 7
- How Robots Will Steal Your Jobgoose wrote:
> until AI people can give us something which does not need them to
> "pull the strings to set it into motion", then i think that they
> are only merely playing games.
I think that's the point of neural nets. You just develop a general
mechanism that "learns" from input--similar to how our brains do.
We aren't anywhere near achieving the complexity of the human brain,
yet, but we will get there eventually.
And THEN we'll see if true intelligence is an emergent property of
complexity (possibly) or whether it requires something more than
mere machinary (possibly).
Until then, we're all just guessing. (-:
> no, it only gets emotional when you accuse everyone on the group
> of species vanity. thus far you have twice told an agnostic that
> their "religion" is preventing them from recognising that others
> (creatures) have intelligence. good job!!
The irony is that I believe Mr. Green experienced what most
theologians would call a "conversion experience" (with dolphins)
and now, like many, many of the converted, is something of a
fanatic on the matter. His posts have more a sense of preaching
than of discussing, and--as you note--he is intolerant of the
"non-believers".
[shrug] Which is fine. Takes all types to make a world, and it's
good to have people on the Side of the Animals. As you can see
from the volume, the thread has certainly captured people's interest.
--
|_ CJSonnack <email***@***.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|_______________________|
- 8
- Refusing TCP connections - ServerSocketI want to create a ServerSocket.
I want it to accept one connection.
If another connection request comes in, I want it to be refused, not queued.
Even if I set backlog to 1, on the OS I'm testing on (Linux) I'm able to
queue up a bunch more connections (5 or 6).
I know the actual backlog size is OS dependent even if I explicitly set it
in the ServerSocket constructor.
So, how do I refuse all subsequent connections after I accept that first one?
--
Steve Sobol, Victorville, CA PGP:0xE3AE35ED www.SteveSobol.com
Geek-for-hire. Details: http://www.linkedin.com/in/stevesobol
- 9
- java.lang.NoClassDefFoundError when calling method from EJBI have a java app that runs on Websphere 6.0 and I needed a way to run
a scheduled task once a day that sends out emails. I used the
following link from IBM's site to develop a stateless EJB session bean
that ran the WAS task scheduler.
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/scheduler/tasks/tsch_schedulebtask.html
I placed a call in the implemented process method (just like the
example says) to a non-EJB method and I get a
java.lang.NoClassDefFoundError error on the method I am tryign to call.
I'm new to EJB so I'm not sure if you can even make a call from an EJB
to a normal (non-EJB) method. Any help would be appreciated.
- 10
- help with image display gui
hi wondered if anyone can help i want to create a dummy gui which looks
like a media player eg transition window buttons etc and have created
them as jpeg can someone help me in understanding how to inport them
into jframes etc and place there positions on the grid,
can gridbag place static images.is there any tutorials to do?
- 11
- How to determine the PID of your Java programHi
I was unable to find a decent How-To for finding the PID of a Java
program running on Windows, that did not use JNI. Here is a solution
that uses netstat.
Hope this is useful. If you have a better strategy, let me know!
Thanks
Andrew
package pid;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.SocketTimeoutException;
/**
* Program to obtain the Process Identifier (PID) of the running Java
program
* Assumes the Windows program
* @author Andrew Ward
*/
public class GetPID {
public static void main(String[] args) {
getPid();
}
/**
* Obtain the PID, by listening on a port, then using netstat -ano
* to find the PID of the processing listening on the port
* @return the pid of this process
*/
public static int getPid() {
// Select a port between 50000 and 51000
final int port = 50000 + (int) (Math.round(Math.random() * 1000));
// Windows specific command line
// Netstat -ano will return many lines, one of which will match
// TCP 0.0.0.0:<port> 0.0.0.0:0 LISTENING
<pid>
final String cmd = "netstat -ano";
final String criteria = "0.0.0.0:" + port;
// Listen on the port for 5 seconds
new SocketListener(port, 5 * 1000).start();
int pid = -1;
try {
// Run netstat
Process process = Runtime.getRuntime().exec(cmd);
InputStream istr = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(istr));
String str;
while ((str = br.readLine()) != null) {
if (str.indexOf(criteria) > 0) {
String match = str.substring(1+str.lastIndexOf(" "));
pid = Integer.valueOf(match);
System.out.println("PID: " + pid + " {" + str + "}");
}
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
return pid;
}
/** listen on a socket */
public static class SocketListener extends Thread {
int port;
int wait;
public SocketListener(int port, int wait) {
this.port = port;
this.wait = wait;
}
public void run() {
try {
ServerSocket server = new ServerSocket(this.port);
server.setSoTimeout(this.wait);
server.accept();
server.close();
}
catch(SocketTimeoutException e)
{
// We are expecting the accept() call to timeout
// so ignore this exception
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
}
}
- 12
- cannot start application server 8 ?installed the Sun Java System Application Server 8 recently. I run the
"asadmin start-domain --verbose domain1" command to try to start it,
however, it didn't happen. i'm using windows 2k server SP$.
thank's!
--
AbdelHalim MIMOUNI
- 13
- How to add a button next to title at the JTabbedPaneHi,
I want to add a small button next to the title of each tabbed pane and
receive user's mouse click event at the small button.
And finally, the selected pane will be removed.
How to add other object, button, into Title part of JTabbedPane ?
Any ideas?
- 14
- Poserpoint slide file (PPS) open with wired characters in jspI included a PPS file as a hyperlink in the jsp file that was
developed in Weblogic 8.1.4 on Windows 2000 platform. However, when I
clicked the file, it opened it with strange characters file contents.
The same file opened correctly under ASP format as a same hyperlink
file. I have never need to specify filetype in ASP. Search couple
hours on Web, could not find any clue, not even a topic talked about
similar subject. Can anyone help? Thanks.
C Chang
- 15
|
|
|