 |
 |
Index ‹ java-programmer
|
- Previous
- 1
- Read data from CSV FileHi all. I am currently trying to develop a program that will read data
from a CSV file which includes computer names that have been exported
from Active Directory. I want my java program to read in the CSV file
and get the data and place it into the JList.
Is this possible.
Any help in this matter would be highly appreciated.
Thank you
- 2
- >>>> Sr Java Dev position in MD -- $85/hr <<<<<Hello all!
I'm Anna Rocheva, a recruiter with USTAS Technologies. I'm glad to
present you a challenging opportunity.
Our direct client is a large reputed financial organization based in
Rockville MD, Washington DC Metro area. We are looking for Sr. Java
Engineer who will develop and support a mission-critical J2EE
applications.
Required skills:
?5-7 years of experience of
o OO design and development
o Hard-core Java development
?5-7 years of experience with the following technologies:
o Java (J2EE, Struts, tag library, Servlets, JSP)
o XML
o Web-based applications
o Ant
o SQL
o Oracle
o Unix/Linux
?2+ years of experience with the following technologies:
o Spring framework
o Hibernate
o AJAX
Agile software development practices
?Excellent communication and writing skills
?Product development methodologies
?Experience using software development best practices
?Experience using open source technologies
Compensation:
Up to $90/hr on c2c and $85/hr on w2..
We have outstanding benefits, e.g. 100% family medical insurance, 401K
plan, paid vacations etc.
If you think that the position requirements match your technical
background and expectations, don't hesitate to contact Anna at
301-242-5033 or via email: email***@***.com
- 8
- jdk 1.5 on linuxHi.
Anybody tried jdk 1.5 on linux ?
I downloaded it, but I can't use any of new features.
Example : Generics
import java.util.*;
class test {
List<String> list = new ArrayList<String>();
}
this class compile fine on jdk 1.5 on Windows, but make on error on
linux :
> ./java -version
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
> ./javac test.java
test.java:4: <identifier> expected
List<String> list = new ArrayList<String>();
^
1 error
on windows, java -version returns
C:\Documents and Settings\Mike>java -version
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode,
sharing)
I downloaded the 2 version (windows & linux) together.
Sun says that linux version is also a beta2 version but that's not
what "java -version" report.
So, anybody having the same problem or an idea on what happened ?
Thansk in advance.
Mike
- 8
- Manifest.mf Class-path troubleHi group!
I'm deploying an application with this structure
app
app/app.bat
app/lib/app.jar
app/lib/another.jar
app/plugins/other/
where the (windows) batch file starts the application like so:
java -jar lib\app.jar
and the Manifest.mf with that jar puts another jar on the classpath
like so:
Class-Path: another.jar
Now I also want to put any plugin classes that users put into
app/plugins/other/ onto the classpath, roughly like so:
Class-Path: another.jar "../plugins/other/*"
So far I've tried a few variations, but the development cycle is quite
tedious and it ain't workin yet.
I'm wondering:
* use quotes ?
* forward slashes ok on windows or do I need separate versions for Win
vs Unix ?
* end the directory with / (or resp. \) or nothing (../plugins/other) ?
* end the directory with "/*" or possibly "/*.class" ?
Alternatively I could use the java -classpath arg in the batch file,
but I've tried that and it's not working either, so I'm getting the
impression that using the Class-path: line in the manifest somehow
disables the -classpath arg of the java command. Is that so?
YT
- 8
- ImageIO.read(url)Hi,
I have an applet with this operation, from the Eclipse it is running without
problem.
When I upload to the web, I receive an "access denied".
Then I find that i need a signed applet. I signed the applet in a jar file,
and uploaded again.
The communication between java & javascript is working, but I continue
receiving the "access denied" error.
How can I set the security permissions to allow the applet to load the image
from an URL that is in another server ?
I need to use another object to read the image ?
Thanks to all.
- 8
- Java localization on MacDear developers,
I made a Java application. I packed it as an ".app" container using Jar
Bundler, then I launched the ".app" and I saw that the standard menu
(the one with About and Quit commands) is in English and not in my
system's default language. How can I get it localized?
Thank you :)
- 8
- help with my first project on first job, how to read a strange file, thanks a lot!!!!!!!the OS is mainly windows. i doubt windows has powerful tool to do the
job automatically.
i need to open and close the file frequently because another process
is writing to the file. then Java create a new object each time I open
the file. in this case, can the program remeber the position I set
last time?
if yes, can i do the same thing with BufferedReader class instead of
RandomAccessFile. i am not sure whether RandomAccessFile can easily
allow me to keep the new line characters and white space among the
valid text. i need these chars in the application. The length() can
not help me a lot, since the file size does not change when new text
is written into the file. the new text write over the whitespace but
do not change the file size.
thanks again!
Alex Kizub <email***@***.com> wrote in message news:<email***@***.com>...
> You didn't mention OS. Probably it could be solved only by OS tools.
> For example for UNIX like it could be grep, tail -f, awk... |, >
>
> Java has other features, but since you can't change application and should
> only change the file (which is not good solution itself) here are some
> solutions for you.
>
> Use java.io.RandomAccessFile.
> So you can set position which you alreadu reached with method seek, you
> can know length of new open file with method
> length().
> Then, I suggest, read file with method read(byte[] b) copy none white
> spaces to another array and write it to the new file.
> Pretty easy.
>
> BTW. With java.io.File you can understand last modification time and
> decide do you need reread file again.
>
> Good luck in your new job.
> Alex Kizub.
> matt wrote:
>
> > Java guys:
> > this is my first project at my first job. so pls help if you could.
> > i am working with a text file with strange format. The file has a lot
> > of white space between the last line of valid text and the end of
> > file character. And the file is update frequently. New valid text is
> > appended behind the original valid text and overwrite some whitespace.
> > I need to feed this file as an input to an application. but this
> > application only take files without such whitespace. The application
> > need to read the file frequently to see whether new text is appended.
> > if there is, get the appended text.
> > My initial solution is to convert the original file into a new file in
> > which the whitespace is truncated. then the application can read the
> > new file.
> > possibility 1:
> > loop
> > read 1 line of text of original file
> > write this line to new file
> > until read the long line of white space
> > close both file
> >
> > in this case, what class and method should i use, especially in
> > examing the white spaces?
> >
> > possibility 2:
> > the previous one is not smart because the same text is read and write
> > each time when the file is read. so is there a way i can just each
> > time check whether update happens to the file and then just write the
> > update to the new file? such as in C, a file pointer know the position
> > of last read. can i do the same in Java or C#? or other ways to do it?
> > possibility 3:
> > very unlikely but smarter,
> > read the file in a stream, truncate the whitespace inside the
> > stream, then feed the stream directly into the application. but it is
> > unlikely because i can not change the souce code the application.
> >
> > any other possibilies to solve this problem?
> > for all the possibilities, pls tell me what class and method should i
> > use, sample code and website is extremely helpful.
> > thanks a lot!!!!!
- 8
- nio sockets + SetTcpNoDelay Exception...Hi,
I use Nio sockets in a production projet for a while, without a single
problem.
Today, without having made any change to the code, I had the bad surprise to
see the following exception in my logs :
java.lang.ClassCastException
at sun.nio.ch.OptionAdaptor.<init>(OptionAdaptor.java:27)
at sun.nio.ch.SocketAdaptor.opts(SocketAdaptor.java:253)
at sun.nio.ch.SocketAdaptor.setTcpNoDelay(SocketAdaptor.java:258)
at aks.net.AKSAcceptDaemon.run(AKSAcceptDaemon.java:135)
My code looks like : (file AKSAcceptDaemon.java)
Selector m_acceptSelector ;
... // selector initialisation
while (m_bRunning)
{
Set readyKeys ;
Iterator it ;
SelectionKey sk ;
ServerSocketChannel ssc ;
SocketChannel client;
while ( m_acceptSelector.select() > 0)
{
readyKeys = m_acceptSelector.selectedKeys();
it = readyKeys.iterator();
// Walk through the ready keys collection and process
date requests.
while (it.hasNext())
{
sk = (SelectionKey)it.next();
it.remove();
if (sk.isAcceptable())
{
ssc = (ServerSocketChannel)sk.channel();
client = ssc.accept();
client.configureBlocking(false) ;
// HERE IS THE GUILTY LINE
client.socket().setTcpNoDelay(false);
// HERE ENDS THE GUILTY LINE
client.socket().setKeepAlive(false);
m_engine.addNewClient(client) ;
}
}
}
}
}
Does someone see what can be the reason of this ?
I made a search on newsgroups, but didnt' found any answer.
Thanks in advance,
Cam
PS : sorry for my crap english : I'm french and frenchies have never been so
good at foreign languages :p
- 8
- Pipelining COM portsIs it possible to create a pipeline to virtual COM port (MS Windows)?
I connect a mobile phone to PC over Bluetooth and
[CommPortIdentifier.getPortIdentifiers();] does not enumerate any port,
neither COM1 nor virtual port for mobile phone.
If I use [new FileOutputStream("COM10");] then I can send data to
mobile phone but I can't read the response.
Basically, I need to open a pipeline to file. Where can I find more
information on this topic?
- 11
- Programming with JCo (SAP)Hi,
I hope there is someone out there with programming experiences in SAP
over Jco.
Unfortunately I have no SAP System here to test my code with.
In the documentation is written:
------
JCO.Repository mRepository;
mRepository = new JCO.Repository("ARAsoft", mConnection);
We invoke the constructor for JCO.Repository with two parameters; the
first one is an arbitrary name, the second one either a connection pool
name or a JCO.Client object. In other words: Both connection pooling and
direct connections are supported. In (web) server applications, we
should always use a connection pool for the repository. The userid used
for the repository has to have sufficient authorizations in SAP for the
metadata access to be possible. Please read the Javadoc for class
JCO.Repository to find out which specific authorizations are required.
You can use one special userid for the repository access and one or more
"normal" userids for the actual application.
------
I have the following code I was able to test on a foreign system:
public JCO.Function getFunction(String repositoryName, String
functionName,
JCO.Client connection) {
IRepository repository =
JCO.createRepository (repositoryName, connection);
IFunctionTemplate ft = repository.getFunctionTemplate (functionName);
return ft.getFunction ();
}
To create the Repository I pass an object of type JCO.Client. I have got
this object from a pool before.
When I understand the documentation corretly I can also pass the pool to
create a Repository. Then there wouldn't be no need to handle with
JCO.Client objects.
But I can not test this and thus I want ask if someone can confirm that
this works.
And another question: Since I don't need any Client objects then, I can
not release them to the pool. Is that ok and happens implicitely, or do
I have to do something else?
--
bye Armin
- 11
- JavaMail GNUMail, Knife, Classpath and gnu.inetOk, here is the deal. I am trying to install a ready to go NNTP
provider for jmail. This lead me to the Knife project, which lead me to
GNU mail which lead me to Project classpath which has led me to a huge
patchwork of downloads.
Has anyone else tried to get this all working? I know for sure that the
code modules I downloaded are not compatible with eachother. One set of
code, for example, is calling on constructors and methods with wrong
method signatures.
Does anyone have something to say on this? Am I missing something? Open
Source is fairly good at avoiding this sort of thing, but then again...
<a href ="http://christian.bongiorno.org/resume.pdf">Christian
Bongiorno</a>
Come get me google!
- 12
- Font Faces and Styles Not SetI'd like to see if anyone can offer an explanation for some font
issues before I report the issues as bugs to Sun and Apple. Please let
me know if you can explain the following as correct behavior.
It appears to me that a lot of fonts simply don't work under Java 1.4.
The simple application below should show fonts with a normal face,
bold, italic and underline. Underline seems to work on all systems,
but on both Windows and OS/X, bold and italic fail on many fonts. The
same fonts seem to have bold and italic faces in non-Java
applications, so it appears to be a problem with the JVM. For example,
STENCIL on the Mac and Century on Windows both have distinct bold and
italic faces in Word, but not in Java.
On OS/X, many fonts do not display the proper face; they seem to
default to serif or sans serif. Most of the Lucida fonts show this
problem.
Mike Westerfield
--- main.java ---
package fonttest;
public class Main {
public Main() {
Window window = new Window();
window.show();
}
public static void main(String[] args) {
Main main1 = new Main();
}
}
--- window.java ---
package fonttest;
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class Window extends JFrame {
private JScrollPane jScrollPane1 = new JScrollPane();
private JTextPane jTextPane = new JTextPane();
public Window() {
try {
jbInit();
pack();
populate();
} catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jScrollPane1.setPreferredSize(new Dimension(640, 480));
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setTitle("Font Test");
this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextPane, null);
}
private void populate () {
String defaultFont = "SanSerrif";
String[] fontNames =
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
for (int f = 0; f < fontNames.length; ++f) {
jTextPane.getCaret().setDot(Integer.MAX_VALUE);
setFont(defaultFont, false, false, false);
jTextPane.replaceSelection(fontNames[f] + "\t");
jTextPane.getCaret().setDot(Integer.MAX_VALUE);
setFont(fontNames[f], false, false, false);
jTextPane.replaceSelection("Abcdef" + "\t");
jTextPane.getCaret().setDot(Integer.MAX_VALUE);
setFont(fontNames[f], true, false, false);
jTextPane.replaceSelection("Abcdef" + "\t");
jTextPane.getCaret().setDot(Integer.MAX_VALUE);
setFont(fontNames[f], false, true, false);
jTextPane.replaceSelection("Abcdef" + "\t");
jTextPane.getCaret().setDot(Integer.MAX_VALUE);
setFont(fontNames[f], false, false, true);
jTextPane.replaceSelection("Abcdef" + "\n");
}
}
private void setFont(String name, boolean bold, boolean italic,
boolean underline) {
SimpleAttributeSet font = new SimpleAttributeSet();
font.addAttribute(StyleConstants.FontFamily, name);
font.addAttribute(StyleConstants.FontSize, new Integer(16));
font.addAttribute(StyleConstants.Bold, new Boolean(bold));
font.addAttribute(StyleConstants.Italic, new Boolean(italic));
font.addAttribute(StyleConstants.Underline, new
Boolean(underline));
jTextPane.setCharacterAttributes(font, false);
}
}
- 12
- NumberFormatException:please help me......!!!Hi,
i have a question and i need your help.
I'm developing a java application that have to import data from a txt
file as
3.2 2.1 4.5 6.7 2.3 4.5 3.4 5.5
2.1 3.2 4.7 2.1 3.5 6.7 5.6 3.1
The application counts rows number and columns number and import data
into a bidimensional array of double type.
I compile my code and i have this error
Exception in thread "main" java.lang.NumberFormatException: For input
string: "3
..2 2.1 4.5 6.7 2.3 4.5 3.4 5.5"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown
Source)
at java.lang.Double.parseDouble(Unknown Source)
at AddDb.ReadArray(AddDb.java:51)
at AddDb.main(AddDb.java:97)
How can i do?
Please help me with code, i'm a new java user...
Here is my code
import java.util.*;
import java.io.*;
public class AddDb {
private static String fileName="Dato.txt";
private static int Ncolumns=0;
private static int Nrows=0;
public int ColumnsNumber(BufferedReader br)throws IOException {
String line = br.readLine(); //legge una linea di testo terminata
da /n o /r e la restituisce come stringa
StringTokenizer st = new StringTokenizer(line);
Ncolumns=st.countTokens();
return Ncolumns;
}
public int RowsNumber(BufferedReader br)throws IOException {
String line = br.readLine();
while (line != null) {
Nrows++;
line = br.readLine();
}
return Nrows;
}
public double[][]ReadArray(int Nrows,int Ncolumns,BufferedReader
br)throws IOException
{
double[][]x=new double[Nrows][Ncolumns];
for(int i=0; i<Nrows; i++)
{
StringTokenizer tok=new StringTokenizer(br.readLine(),"");/
for(int j=0; j<Ncolumns; j++)
{
x[i][j]=Double.parseDouble(tok.nextToken().trim()) }
}
for(int i=0; i<Nrows; i++)
{
for(int j=0; j<Ncolumns; j++)
{
System.out.println("L'array bidimensionale ?+x[i][j]);
}
}
return x;
}
public static void main(String[] args)throws IOException {
FileReader file = new FileReader(fileName); BufferedReader br =
new BufferedReader(file);
AddDb db=new AddDb();
br.mark(99999);
db.ColumnsNumber(br);
System.out.println("Il numero di colonne e' :"+Ncolumns);
br.reset();
br.mark(99999);
db.RowsNumber(br);
System.out.println("Il numero di righe e' :"+Nrows);
br.reset();
System.out.println("Caricamento dell'array di double in
corso.....");
try
{
System.out.println(db.ReadArray(Nrows,Ncolumns,br));
}
catch(IOException e){
System.out.println(e.getMessage());
}
br.close();
}
}
- 15
- ZoneView: does it work?I'm going to repeat a question that i've asked in javalobby to no
avail.
Did anyone ever got zoneview working for a JEditorPane and if so how?
I'm using a custom stylededitorkit that implements view factory and my
factory code looks like this:
public View create(Element elem) {
String name = elem.getName();
if (name != null) {
if (name.equals(AbstractDocument.ContentElementName)) {
return new LabelView(elem);
} else if (name.equals(AbstractDocument.ParagraphElementName)) {
return new CountingParagraphView(elem,observer);
} else if (name.equals(AbstractDocument.SectionElementName)) {
return new ZoneView(elem, View.Y_AXIS);
} else if (name.equals(StyleConstants.ComponentElementName)) {
return new ComponentView(elem);
}else if (name.equals(StyleConstants.IconElementName)) {
return new IconView(elem);
}
}
return new LabelView(elem);
}
Ignore the contngparagraph view, its just something i did to be able to
tell the amount of text visible.
Using zoneview here gives an nullpointerexception in the guts of swing,
in AsyncBoxView i think.
I'm just looking for a way not to load to the views the entire text at
a time (That is sloooow). And getting an indicator of the index of
text. I'm going to append my editor kit and textpaintobserver if you
want to see how it works (to make it work, just replace zoneview with
boxview in the method above).
/**
*
*/
package ui;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Shape;
import javax.swing.SwingUtilities;
import javax.swing.text.AbstractDocument;
import javax.swing.text.BoxView;
import javax.swing.text.ComponentView;
import javax.swing.text.Element;
import javax.swing.text.IconView;
import javax.swing.text.JTextComponent;
import javax.swing.text.LabelView;
import javax.swing.text.ParagraphView;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledEditorKit;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
class TextCountingEditorKit extends StyledEditorKit implements
ViewFactory{
/**
* Observer given in the constructor.
*/
private final TextPaintObserver observer;
private static final long serialVersionUID = -7828351555750309111L;
public TextCountingEditorKit(TextPaintObserver observer) {
super();
this.observer = observer;
}
public ViewFactory getViewFactory()
{
return this;
}
public View create(Element elem) {
String name = elem.getName();
if (name != null) {
if (name.equals(AbstractDocument.ContentElementName)) {
return new LabelView(elem);
} else if (name.equals(AbstractDocument.ParagraphElementName)) {
return new CountingParagraphView(elem,observer);
} else if (name.equals(AbstractDocument.SectionElementName)) {
return new ZoneView(elem, View.Y_AXIS);
} else if (name.equals(StyleConstants.ComponentElementName)) {
return new ComponentView(elem);
}else if (name.equals(StyleConstants.IconElementName)) {
return new IconView(elem);
}
}
return new LabelView(elem);
}
/**
* Counting paragraph view
*/
class CountingParagraphView extends ParagraphView {
private Rectangle line;
private Rectangle win;
private TextPaintObserver observer;
public CountingParagraphView(Element elem, TextPaintObserver
observer){
super(elem);
//strategy = new MyFlowStrategy(); TODO
line = new Rectangle();
win = new Rectangle();
this.observer = observer;
}
/**
* Overrides the normal paint method for eliminating
* cut lines at the top and bottom of the viewport
* and for counting the number of visible chars from
* the model (without added \n from line-wrap,or tabs)
* the visible chars are derivated by subtracting
* two variables of the class, first and last,
* who this method updates, and who is the responsability
* of the component that wants to know them to rest afterwards
* @param g
* @param a
*/
public void paint(Graphics g, Shape a) {
Rectangle box = (a instanceof Rectangle) ? (Rectangle)a :
a.getBounds();
SwingUtilities.calculateInnerArea((JTextComponent)getContainer(), win);
int n = getViewCount();
int x = box.x;
int y = box.y;
for (int i = 0; i < n; i++) {
line.x = x + getOffset(X_AXIS, i);
line.y = y + getOffset(Y_AXIS, i);
line.width = getSpan(X_AXIS, i);
line.height = getSpan(Y_AXIS, i);
View view = getView(i);
//g.draw3DRect(line.x,line.y,line.width,line.height,true);
if ( win.contains(line) ) {
int startOffSet = view.getStartOffset();
//Lame document default behavior workaround (see
AbstractDocument)
int endOffSet = (view.getEndOffset() >
getDocument().getLength() ) ? view.getEndOffset()-1:
view.getEndOffset();
if( startOffSet < observer.getFirst()){
observer.setFirst(startOffSet);
}
if( endOffSet > observer.getLast()){
observer.setLast(endOffSet);
}
paintChild(g, line, i);
}
}
}
}
}
package ui;
import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;
import javax.swing.text.JTextComponent;
public class TextPaintObserver {
private int first;
private int last;
private JTextComponent text;
public TextPaintObserver(JTextComponent text) {
reset();
this.text = text;
}
public void setFirst(int in) {
this.first = in;
}
public void setLast(int in) {
this.last = in;
}
public int getFirst() {
return (this.first == Integer.MAX_VALUE) ? 0 : first;
}
public int getLast() {
return (this.last == Integer.MIN_VALUE) ? 0 : last;
}
/**
* Resets the state of the observed values
*/
private void reset(){
first = Integer.MAX_VALUE;
last = Integer.MIN_VALUE;
}
/**
* Gets the visible length
*/
public int getInterval(){
resetState();
return getLast() - getFirst();
}
/**
* Causes the state of the visible length to
* be updated
*
*/
private void resetState(){
reset();
if(SwingUtilities.isEventDispatchThread()){
text.paintImmediately(text.getBounds());
}
else{
try {
SwingUtilities.invokeAndWait(
new Runnable(){
public void run(){
text.paintImmediately(text.getBounds());
}
}
);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
- 15
- intersection model with threads problemX-No-Archive
Hello,
I am trying to learn java threads, and to attempt an exercise from my
textbook, hwever I am not sure if any of my proposed solutions are in
the right vein...
The problem is to model an intersection with trafficlights and 2
sensors at each trafficlight, one for arriving and entering, and one
for exiting..., and cars as threads.
the time the car stays in for, the length of time it takes the lights
to switch colors, and the number of cars must all be definable and easy
to change..
I was consiering having each car as a thread, and sensors and
trafficlights as a monitors, when a sensor detects a car arriving, it
notifies the trafficlight to change, and trafficlight will block or
allow the car thread to run, ie enter or leave...
I'm not sure if I am even on the right track, and can not find any
example solutions to this problem, so if anyone has any idea I would be
very gratefull
Thanks,
Jason
|
| Author |
Message |
Beth

|
Posted: 2005-10-5 6:41:00 |
Top |
java-programmer, Fast image scaling
Hi all,
I'm writing a program which involves drawing several copies of the same
image inside of a JPanel. I have a listener on the mouse wheel to
"zoom in/out", so that every image scales up or down in size at the
same time. I'm having many problems getting this to run smoothly.
I first tried to scale the image just once (since it is drawn many
times) by calling getScaledInstance, saving the resulting image, and
then drawing that lots of times. However, even though I am using
Image.SCALE_FAST, it sometimes takes a while to update the image when
scaling to larger sizes. (Note, the image is 440x250, and I'm never
scaling it larger than double its size.)
The second thing I tried was to use an AffineTransform to scale the
graphics object just prior to drawing the image. This gave slightly
better results during the actual scaling, but it caused random hitches
(half-second pauses where all movement in the program completely
stops), even when I wasn't actively changing the scale. I finally
deduced that the scaling causes some garbage to be created, and the
hitches happened when the garbage collector ran. (I also tried without
the AffineTransform, and just using the width/height arguments in
drawImage to scale on-the-fly, but the results were the same.) Please
also note that when I don't scale the image at all, the drawing is
perfectly smooth and fast.
What I'm doing doesn't seem to be nearly as intensive as what most
people are capable of doing, so clearly I'm doing something wrong. If
anyone could point me in the right direction, I'd be most appreciative!
Thanks!
|
| |
|
| |
 |
Boudewijn Dijkstra

|
Posted: 2005-10-5 23:58:00 |
Top |
java-programmer >> Fast image scaling
"Beth" <email***@***.com> schreef in bericht
news:email***@***.com...
> Hi all,
> I'm writing a program which involves drawing several copies of the same
> image inside of a JPanel. I have a listener on the mouse wheel to
> "zoom in/out", so that every image scales up or down in size at the
> same time. I'm having many problems getting this to run smoothly.
>
> I first tried to scale the image just once (since it is drawn many
> times) by calling getScaledInstance, saving the resulting image, and
> then drawing that lots of times. However, even though I am using
> Image.SCALE_FAST, it sometimes takes a while to update the image when
> scaling to larger sizes. (Note, the image is 440x250, and I'm never
> scaling it larger than double its size.)
Zooming in is far slower than zooming out. Create a VolatileImage at 2?size
and use that as a master image. Then a create correctly scaled working copy
from that, each time the scale changes.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-6 7:53:00 |
Top |
java-programmer >> Fast image scaling
On 4 Oct 2005 15:40:38 -0700, "Beth" <email***@***.com> wrote or
quoted :
>What I'm doing doesn't seem to be nearly as intensive as what most
>people are capable of doing, so clearly I'm doing something wrong. If
>anyone could point me in the right direction, I'd be most appreciative!
Here is the code I use for allowing you to magnify images. The slider
lets you magnify smoothly. I am doing nothing special. This code
just uses the magnifying ability of drawImage. You might hook this up
and try out to see if it gives you any better than you are getting
now. If so, compare code to figure out what we are doing differently.
package com.mindprod.image;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.MediaTracker;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.prefs.Preferences;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* Displays an image.
User can use a slider to make the
* image bigger or smaller.
*
* @author Roedy Green
* @version 1.0
* @since 2004-04-04
*/
public class MagnaViewer extends JFrame
{
/**
* layout
* ----- slider----- save
* ------image-----------
*
* When image is bigger than fits, it has scroll bars.
*/
/**
* Constructor
*
* @param image image to display
* @param minDim minumim size ever display an image.
* @param maxDim maximum size of the magnified image that we
* scroll over.
* @param saveName suggested name to save the file under, without
* directory.
*/
public MagnaViewer( BufferedImage image, Dimension minDim,
Dimension maxDim, String saveName )
{
this.minDim = minDim;
this.maxDim = maxDim;
this.magnifiedDim = maxDim;
this.saveName = saveName;
setImage ( image );
}
private String saveName;
/**
* the smallest we ever draw an image
*/
private Dimension minDim;
/**
* the largest we allow a magnified image to go, don't necessarily
display it all.
*/
private Dimension maxDim;
/**
* The width of the current Image, unmagnified
*/
private int imageWidth;
/**
* the height of the current image, unmagnified.
*/
private int imageHeight;
/**
* The width of the image as painted,
* may be wider than scrollPane
*/
private int paintedImageWidth;
/**
* The height of the image as currently painted,
* may be taller than scrollPane. Used to avoid
* needlessly repainting the image the same size as before.
*/
private int paintedImageHeight;
/**
* the current magnification we are about to use to paint.
*/
private double magnification;
/**
* how wide the magnified image will be.
* May be wider than the scrollPane.
*/
private int magnifiedImageWidth;
/**
* how tall the magnified image will be.
* May be tall than the scrollPane
*/
private int magnifiedImageHeight;
/**
* how wide and tall the magnified image will be.
* May be bigger than the scrollPane
*/
private Dimension magnifiedDim;
/**
* the image we are displaying
*/
private BufferedImage image;
/**
* slider to control magnification.
*/
private JSlider slider;
/**
* save button to save image to disk
*/
private JButton save;
/**
* scrollPane to allow image to be bigger than frame,
* and let us pan over it.
*/
private JScrollPane scrollPane;
/**
* Panel upon which the image is drawn.
*/
private ImagePanel imagePanel;
/**
* Set or change the current Image to display.
* setImage does a MediaTracker to ensure the Image is loaded.
* You don't have to.
* If you don't plan to use the old image again you should
* do a getImage().flush();
*
* @param image the new Image to be displayed.
* If the image jpg may have recently changed, don't use
* getImage to create it, use
* URL.openConnection()
* URLConnection.setUseCaches( false )
* Connection.getContent
* Component.createImage
*
*/
private void setImage( BufferedImage image )
{
// even if Image object is same, we use it since it may have
changed state.
this.image = image;
if ( image != null )
{
MediaTracker tracker;
try
{
// wait until image is fully loaded.
// and so that paint will be instantaneous, rather than
gradual as
// the image arrives.
// MediaTracker notifies of progress via our
Component.ImageObsever interface
tracker = new MediaTracker( this );
tracker.addImage( image, 0 );
tracker.waitForID( 0 );
}
catch ( InterruptedException e )
{
}
}
imageWidth = image.getWidth( this );
imageHeight = image.getHeight( this );
/* force repaint even if same size */
paintedImageWidth = -1;
paintedImageHeight = -1;
setSliderBounds();
sliderMoved();
} // end setImage
/**
* Set the low and high bounds on the slider.
* Set the slider to no magnification.
*/
private void setSliderBounds()
{
if ( slider == null )
{
return;
}
/* calculate the minium and maximum magnification we will use */
/* slider uses 100 to represent 1.00 magnification */
double minMag = Math.max( (double) minDim.width / (double)
imageWidth,
(double) minDim.height /
(double)imageHeight);
double maxMag = Math.min( (double) maxDim.width / (double)
imageWidth,
(double) maxDim.height / (double)
imageHeight);
slider.setMinimum( (int)( minMag*100.0 + .5 ));
slider.setMaximum( (int)( maxMag*100.0 + .5 ));
slider.setValue( 100 /* 1.00 scaled by 100 */ );
}
/**
* The slider moved. Magnification may have changed.
*/
private void sliderMoved()
{
if ( slider == null )
{
magnification = 1;
}
else
{
magnification = slider.getValue() / 100.0;
// 100 -> 1.00 no magnification
}
magnifiedImageWidth = (int)(imageWidth * magnification + 0.5);
magnifiedImageHeight = (int)(imageHeight * magnification + 0.5);
if ( magnifiedImageWidth != paintedImageWidth ||
magnifiedImageHeight != paintedImageHeight )
{
magnifiedDim = new Dimension( magnifiedImageWidth,
magnifiedImageHeight );
if ( scrollPane != null )
{
// if changes size
// make scrollPane rething whethen it needs scrollbars
scrollPane.setVerticalScrollBarPolicy (
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
scrollPane.setHorizontalScrollBarPolicy (
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
scrollPane.revalidate();
scrollPane.repaint();
}
}
}
private void saveImage ()
{
// ask user where to save.
// persisted in registry directory last used
Preferences userPrefs = Preferences.userRoot().node(
"/xxxxx/magnaviewer" );
File suggestedFile = new File (userPrefs.get( "SAVEDIR", "C:" ),
saveName );
JFileChooser fc = new JFileChooser () ;
fc.setSelectedFile( suggestedFile );
// filter out all but JPG file from view
fc.addChoosableFileFilter( new JpgFileFilter() );
int result = fc.showSaveDialog( this );
switch ( result )
{
case JFileChooser.APPROVE_OPTION:
File file = fc.getSelectedFile();
try
{
// magnify which has side effect of turning back to
plain Image.
Image magnifiedImage
= image.getScaledInstance( magnifiedImageWidth,
magnifiedImageHeight,
BufferedImage.SCALE_SMOOTH);
// convert back to BufferedImage
BufferedImage bufferedImage = new BufferedImage (
magnifiedImageWidth,
magnifiedImageHeight,
BufferedImage.TYPE_INT_BGR );
bufferedImage.createGraphics().drawImage(
magnifiedImage, 0, 0, this /* observer */ );
// write out the BufferedImage as a JPEG
ImageIO.write( bufferedImage,
"JPEG" /* format desired */ ,
file );
}
catch ( IOException e )
{
Log.println( Log.NON_FATAL_ERROR, "Image file not saved
successfully." );
}
// save same directory for next time.
// persisted in registry directory last used
userPrefs.put( "SAVEDIR",
fc.getCurrentDirectory().getAbsolutePath() );
break;
case JFileChooser.CANCEL_OPTION:
case JFileChooser.ERROR_OPTION:
break;
default:
}
}
/**
* second stage of initialisation.
*/
public void addNotify()
{
super.addNotify();
Container contentPane = this.getContentPane();
contentPane.setLayout( new GridBagLayout() );
// dummy, will be set to better values. as soon as image size
known.
slider = new JSlider( JSlider.HORIZONTAL, 10 /* low */ , 300 /*
high */ , 100 /* init */);
slider.setPaintTicks( false );
slider.setPaintLabels( false );
slider.setPaintTrack( false );
save = ResourceGetter.createTransparentGifButton( "save", this
);
imagePanel = new ImagePanel();
// default uses bars as needed.
scrollPane = new JScrollPane( imagePanel );
// x y w h wtx
wty anchor fill T L
B R padx pady
contentPane.add( slider, new GridBagConstraints( 0, 0, 1, 1,
1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new
Insets( 2, 4, 2, 2 ), 0, 0 ) );
// x y w h wtx
wty anchor fill T L
B R padx pady
contentPane.add( save, new GridBagConstraints( 1, 0, 1, 1, 0.0,
0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets( 2,
4, 2, 2 ), 0, 0 ) );
// x y w h
wtx wty anchor fill T L B R padx pady
contentPane.add( scrollPane, new GridBagConstraints( 0, 1, 2, 1,
1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new
Insets( 2, 4, 2, 2 ), 0, 0 ) );
hookListeners();
setSliderBounds();
sliderMoved();
validate();
}
/**
* attach various listeners.
*/
private void hookListeners()
{
hookSlider();
hookSaveButton();
hookWindowClosing();
}
/**
* hook up listener for slider
*/
private void hookSlider()
{
// user changed the slider
ChangeListener sliderListener = new ChangeListener()
{
/**
* Invoked when the target of the listener has changed its
state.
*
* @param event not used
*/
public void stateChanged( ChangeEvent event )
{
sliderMoved();
}
};
slider.addChangeListener( sliderListener );
}
/**
* hook up listener for save button
*/
private void hookSaveButton()
{
ActionListener saveListener = new ActionListener()
{
/**
* invoked when save button hit.
*
* @param e event used to figure out which button was
pressed.
*/
public void actionPerformed( ActionEvent e )
{
saveImage();
}
};
save.addActionListener( saveListener );
}
/**
* create and attach anonymous inner class event handler for window
closing.
*/
private void hookWindowClosing()
{
this.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
// what happens when user closes the LiveFeedFrame.
WindowListener windowListener = new WindowAdapter()
{
/**
* anonymous WindowAdapter class
*
* @param w not used
*/
public void windowClosing ( WindowEvent w )
{
if ( image != null )
{
image.flush();
}
MagnaViewer.this.dispose();
} // end windowClosing
}; // end anonymous class
this.addWindowListener( windowListener );
} // end hookWindowClosing
/**
* inner class panel with just the image
*
* @author Roedy Green
* @version 1.0
* @since 2004-05-04
*/
class ImagePanel extends JPanel
{
/**
* custom paint, draws the Image
*
* @param g graphics representing screen where image
displayed.
*/
public void paintComponent ( Graphics g )
{
super.paintComponent( g );
/* If we overflow, no problem, drawImage will clip. */
// this does not complete the job, just starts it.
// We are notified of progress through our Component
ImageObserver interface.
Dimension dim = getSize();
// centre in panel. If too big to fit put it upper left
corner and let
// scroll deal with the slop.
g.drawImage ( image, /* Image to
draw */
Math.max( 0, ( dim.width - magnifiedImageWidth
) / 2), /* x */
Math.max( 0, ( dim.height -
magnifiedImageHeight ) / 2), /* y */
magnifiedImageWidth, /* width */
magnifiedImageHeight, /* height */
this ); /* this
ImagePanel component */
paintedImageWidth = magnifiedImageWidth;
paintedImageHeight = magnifiedImageHeight;
}
/**
* Preferred Layout size.
*
* @return the recommended dimensions to display the Image.
*/
public Dimension getPreferredSize()
{
return magnifiedDim;
}
/**
* Minimum Layout size.
*
* @return the recommended dimensions to display the Image.
*/
public Dimension getMinimumSize()
{
return magnifiedDim;
}
/**
* Maximum Layout size.
*
* @return the recommended dimensions to display the Image.
*/
public Dimension getMaximumSize()
{
return magnifiedDim;
}
} // end ImagePanel
}
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-6 8:51:00 |
Top |
java-programmer >> Fast image scaling
On Wed, 5 Oct 2005 17:58:06 +0200, "Boudewijn Dijkstra"
<email***@***.com> wrote or quoted :
>Zooming in is far slower than zooming out. Create a VolatileImage at 2?size
>and use that as a master image. Then a create correctly scaled working copy
>from that, each time the scale changes.
Zooming in means magnifiying as if you were getting closer to the
image. It has to create new pixels by interpolation. Zooming out is
easier. You are dropping data.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-6 9:00:00 |
Top |
java-programmer >> Fast image scaling
On Wed, 5 Oct 2005 17:58:06 +0200, "Boudewijn Dijkstra"
<email***@***.com> wrote or quoted :
>Zooming in is far slower than zooming out. Create a VolatileImage at 2?size
>and use that as a master image. Then a create correctly scaled working copy
>from that, each time the scale changes.
You actually have to create two images, a VolatileImage and backup to
reconstruct the Volatile image in case it is lost. One of the
annoyances of a VolatileImage is the video card hardware might at any
time decide it needs its RAM for a higher priority purpose.
VolatileImage is the ultimate in speed since the image is stored the
proprietary format of the video card inside the video card and has
access to the image processing hardware in the card for copying or
magnifying. Some cards have 512-bit processors, and bit
addressability compared with 32-bit for a Pentium.
I did one program that way for smooth scrolling of a giant video
display for the Las Vegas Hilton. Ironically, to create the illusion
of majestic smoothness, you need to be very fast.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
Beth

|
Posted: 2005-10-7 1:29:00 |
Top |
java-programmer >> Fast image scaling
Thanks so much for your help everyone.
I've tried the VolatileImage method, and it seemed to be faster, until
I created the VolatileImage with transparency... then my garbage
collection pauses came back for some odd reason.
I also tried out the demo code, Roedy, and it was blindingly fast. I
haven't found anything in the code that looks very different from mine,
so now I am starting to worry that my garbage collection problems may
be caused by something that isn't image-scaling related (although
changing image scaling methods does affect it...).
Another note: I was testing all this code (including Roedy's) on a
Linux AMD64 machine. When I tried it on my Win2k machine, my garbage
collection problems disappeared. More investigation seems necessary.
Thank you!
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-7 3:21:00 |
Top |
java-programmer >> Fast image scaling
On 6 Oct 2005 10:28:33 -0700, "Beth" <email***@***.com> wrote or
quoted :
> More investigation seems necessary.
>Thank you!
There are profilers to help you sort this out. It make be some
platform specific code is "frothing" -- spitting out millions of tiny
objects.
http://mindprod.com/jgloss/profiler.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
Thomas Fritsch

|
Posted: 2005-10-7 19:51:00 |
Top |
java-programmer >> Fast image scaling
Roedy Green wrote:
> There are profilers to help you sort this out. It make be some
> platform specific code is "frothing" -- spitting out millions of tiny
> objects.
Ironically BufferedImage.getRGB(int x, int y) itself is such a "frothing
monster". It creates a tiny temporary pixel object (typically a new
byte[3] array in case of RGB image) each time it is called.
I found this, when I profiled an image processing application of mine,
which made heavy use of getRGB(x,y).
My work-around was to avoid
int rgb = image.getRGB(x, y);
but instead define a member variable
private Object pixelData = null;
and to reuse that object for each pixel of the image
pixelData = image.getRaster().getDataElements(x, y, pixelData);
int rgb = image.getColorModel().getRGB(pixelData);
I got an incredible performance-boost this way.
--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
|
| |
|
| |
 |
Andrey Kuznetsov

|
Posted: 2005-10-8 2:52:00 |
Top |
java-programmer >> Fast image scaling
> My work-around was to avoid
> int rgb = image.getRGB(x, y);
>
> but instead define a member variable
> private Object pixelData = null;
> and to reuse that object for each pixel of the image
> pixelData = image.getRaster().getDataElements(x, y, pixelData);
> int rgb = image.getColorModel().getRGB(pixelData);
>
> I got an incredible performance-boost this way.
really good idea!
Thanks Thomas!
--
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-10-8 9:17:00 |
Top |
java-programmer >> Fast image scaling
On Fri, 07 Oct 2005 11:51:01 GMT, Thomas Fritsch
<email***@***.com> wrote or quoted :
>My work-around was to avoid
> int rgb = image.getRGB(x, y);
>
>but instead define a member variable
> private Object pixelData = null;
>and to reuse that object for each pixel of the image
> pixelData = image.getRaster().getDataElements(x, y, pixelData);
> int rgb = image.getColorModel().getRGB(pixelData);
thanks Thomas. I have used that code as an example of frothing and
what you can do about it at http://mindprod.com/jgloss/frothing.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Looking for a gui class to pop up to let user choose directory and filenameHi,
When I output something to a file, I hope something pop up that let the
user to select the directory and input the file name. I don't know how
to do it. I can hard-code the file name in my program and use
PrintWriter class to do it, like:
PrintWriter outputStream = new PrintWriter(new FileOutputStream("out.txt"));
outputStream.println("hello world");
outputStream.println("how are you?);
Thank you very much for your help.
- 2
- Beautify HTMLHi,
I need to beautify HTML files from within my web application. These
files come from an online editor that writes its output on a single line.
JTidy might be a solution, but there is no documentation and so it's
very hard to test it on the fly. After all, I don't need a complete
parser: a simple formatter/beautifier would be great. Does anyone know
of such a class? Arachnophilia does it, but it's not an API.
Thanks
Mario
- 3
- Displaying multi-line textHi all,
I want to display text on the screen, I would normally use a JLabel but I
want this text to span over about 3 lines. I am trying to use a JTextArea
but I want the background to be transparent, like the JLabels. I can not
find anywhere in the API on how to do this. Any help or alternative ideas to
using JTextArea would be greatly appreciated.
Many thanks
Ed Keen
- 4
- BigDecimal Builder and immutability...Our application uses BigDecimal, and BigDecimal is immutable. Immutability
is certainly a good thing, but it also means that there are a lot more
memory allocations (and collections). That's ok, we are all happy that
Strings are immutable, but Java also gives us StringBuilder and
StringBuffer. Is there anything similar for BigDecimal?
BigDecimal operations are the hotspots in our application and the GC is also
very busy collecting all the objects. Unfortunately double are not good
enough for us. Ideally we would like something like C# Decimal: a 128bit
decimal number (not floating point, but decimal), I have not actually used
this, but from what I have heard it is what we would need..
I googled the web for a fixed precision decimal class for Java, for an
immutable version of BigDecimal, etc... I could not find anything. Do you
know of anything that could help us?
Thanks,
Tommy
- 5
- Two Jframe`s - how to setenable(fasle) ?I have problem, in my application I have main jframe, now user click on
jbutton, now I create another Jframe with jprogressbar
i would like to block main Jframe. How to do is ?
- 6
- Aspect oriented Everything?Hello,
Aspect oriented Software development seems to be expanding in the
popular vision of developers, with more and more IDE 'add-ons' and
even more specialized tools,Jboss etc.
I've seen more and more languages integrate AOP,AspectJ (Java),
AspectR(Ruby)etc.Aspect oriented does seem to be the place to go from
a developer standpoint.What I want to know is,if anybody on a
commercial scale is using AOSD to develop commercial products? Is an
Open Source development ever going to gain the trust of industry? It
may be ok for personal projects and other Open Source material but
will your bank ever accept it? Is it the fact that AOP is new and, for
most,confusing or is it the fact that AOP has developed in the
environment it has.i.e Open Source,that may dissuade commercial
development shops from accepting AOP.
What are the main features that may lead to AOSD adoption? Is AOP the
next step on from OOP? Is it another chance for some of the lesser
utilised languages to step up to Java and C++? Your opinions on the
subject would be appreciated? Design features are one thing but
widespread adoption is another, or is it?
Anything you care to add on the subject would be appreciated on this
short questionnaire.
http://www.geocities.com/aspect505
Thank you for your participation.
Shane Hassan.
http://www.geocities.com/aspect505
- 7
- Book question on threads"Chris Smith" <email***@***.com> wrote in message
news:email***@***.com...
> Obviously, it's possible to interpret the question in a way that makes
> this answer wrong; it's probably easier, though, to interpret it to make
> this answer right. What you've listed is invalid syntax, and I would
> have a rather strong bias against an interpretation of this question
> that requires you to assume (without seeing code) that the author has
> written code that results in compile-time errors. If that were the
> case, option B should read "the thread was never started because the
> program didn't compile". :)
>
The example had no code. Only the question which I posted. The whole point
of the question though, is to determine which possibilities are... um...
possible.
> To take a guess at a literal explanation, should we assume the author is
> being as literal as you are, the word "access" is very closely related
> to "accessor", the word for a short method that serves to allow someone
> to access a field. More likely, though, the author wasn't excluding
> non-direct access to the variable; the last phrase should instead be
> interpreted as a statement of intent for what the thread wants to do.
>
As I said in my reply to Nigel, questions about programming (similar to
programs about science and math) are very clear-cut. If every word of an
answer isn't true, the answer is incorrect. At least that's how it is in my
experience.
> In the end, when people so frequently post bad questions from
> certification prep books, and it's so widely known that a large majority
> of certification prep books are full of stupid drivel from people who
> confuse the Java language with their own pet mental gymnastics for
> memorizing stuff and possibly also just feel more secure when they ask
> ambiguous questions so that you'll miss some... given all this, why
> would it be a surprise that someone found an ambiguous question in a
> Java certification prep book?
>
No surprise. I just wanted to see if this was indeed one of those ambiguous
questions. Apparently it is. If I saw this question on an actual test, I
think I'd still answer it as I have here, because I haven't really heard a
convincing explanation why not to. It seems that every response either
explicitly or implicitly has something to do with "interpreting the answer"
to mean something slightly different from what it says. I'm still going to
have to stand by my original response to the question: you cannot
synchronize access to a variable. Therefore a thread will never need an
object's monitor in order to access a member variable of that object.
Therefore, a thread will never be waiting on said monitor.
- 8
- Tele-conference demoI know Microsoft has teleconference software, can
do tele-presentation, demo
But I prefer do things simple
I am thinking use java.awt.Robot class do
the screen catch every second, then write
to the image into a buffer file pipe
in web server.
Then in the web page create
an applet read from that buffer file pipe.
So when I doing demo, I start my program run
in background, do screen catch, write to web
server.
User just http to my applet page watch my demo.
This is similar to xwatchwin in X11 world.
But X11 world only work in intranet with small
group of people, require expensive X-terminal.
Today every PC has a browser, access to internet.
Do you think this is doable?
Any better idea?
Or such Java program already existed? (tell me the download link)
Thanks!
- 9
- Webstart ignoring minor J2SE version numbersI'm trying to build my first WeStart aware application. I've JARed it
and assembled my HTML and JNLP files, but am having a lot of trouble
with the <j2se> tag.
I would like my users to use Java 1.4.2 or later. (I have 1.4.2-b28
myself). However, when I use the tag <j2se version="1.4.2+"/>, web
start replys that a JVM of this version is not installed, and that it
cannot find an appropriate JVM to download either. Changing that to
"1.4.2" - the example given in the documentation - creates the same
error. However, "1.4+" download and runs the application.
My app relys on some bug fixes from versions post 1.4.0, and I'd like
my users upgrade to the appropriate JVM. Is there a way to get this
done?
Mark McKay
http://www.kitfox.com
- 10
- finding java difficultI know Visual Basic and few other commands in Oracle but I am having
trouble learning high level Java. Should I just read over and worry
about it later? I understand Arrays and If statements but found for
example, " overiding and hiding methods" difficult. It states a
superclass overides a superclass. I am confused!
here is "overiding and hiding methods" from the sun.com site;
An instance method in a subclass with the same signature and return
type as an instance method in the superclass overrides the superclass's
method. (Remember that a method's signature is its name and the number
and the type of its arguments.) You can also override a method with the
same signature that returns a subclass of the object returned by the
original method. This facility (introduced in 5.0) is called covariant
return type and you can see an example in Annotations (in the Learning
the Java Language trail).
- 11
- MySQL / MS SQL - jsp developmentI am working on a jsp project that uses a MySQL database,
i wonder if the backup (.sql) file of MySQL can be executed on a MS SQL
server.
sorry for sort of off-topic of the forum.
Thanks so much
ran
- 12
- DropDown in cell of jTableHi all,
I wish to put a drop down where to choose from when the user edit a certai
cell of a jTable.
The drop down should appear in the position of the cell thas is going to be
edited....
Is it possible? How?
can someone point me in the right direction? (or send a snippet of code ;) )
Thanks.
Mario
- 13
- Java SDK on Linux (problem)I have a Java SDK (j2sdk1.4.1_02) installed on a Linux system (2.2.14).
All seemed to be going well until I noticed something a bit strange.
Running a java app appears to result in the launch of over a dozen
consecutive processes. Suspecting the possibility of a weird, multi
threaded app, I wrote a small test program, Hello.java (appended below).
Same behaviour. Other than setting the CLASSPATH environment variable
appropriately and unpacking the kit, the system appears to have no other
java-specific configuration settings that I can find.
Any ideas?
// Hello.java
package hovnanian.examples.gui;
import javax.swing.*;
import java.awt.*;
public class Hello extends JFrame {
public static void main(String[] args) {
Hello h = new Hello();
}
public Hello() {
super("Hello");
String message = "Hello world!";
Label lbl = new Label( message );
this.getContentPane().add(lbl);
this.pack();
this.setVisible(true);
}
}
--
Paul Hovnanian mailto:email***@***.com
note to spammers: a Washington State resident
------------------------------------------------------------------
Applying information technology is simply finding the right wrench
to pound in the correct screw.
- 14
- SetProperty per oggetti Complessi Salve a tutti,
sto sviluppando un'applicazione web piuttosto complessa in java che utilizza il framework Bluprint della Sun.
In particolare, la mia problematica è legata alla gestione degli oggetti di business nell'interfaccia con l'utilizzo, nelle jsp, dei metodi setProperty e getProperty java.
Gli oggetti che utilizzo sono i seguenti:
‘public class Anagrafica implements java.io.Serializable {
...
private Vector indirizzi;
}
...
public class Indirizzo implements java.io.Serializable {
protected String tipo;
protected String particella;
protected String address;
protected String houseNumber;
protected String zipCode;
...
}
Ciò che voglio realizzare è la visualizzazione nella jsp dell'interfaccia di tanti ‘frame' quanti sono gli oggetti Indirizzo contenuti nel Vector di Anagrafica. Scrivendo, però, ciò che segue:
<jsp:useBean id="..." class="..." scope="session">
<jsp:setProperty name="indirizzo" property="*"/>,
il metodo setProperty non setta le proprietà complesse dell' oggetto vector indirizzo.
Spero di esser stata chiara.
Attendo un vostro suggerimento...
-------------------------
Annalisa Cosmai
- 15
- Problem with Java panelsI want to write application with few tabbed panels each with split
panel inside. Some of those split panels should share the same panel
as in code below.
//----------------//
JTabbedPane tabbed = new JTabbedPane();
JSplitPane split1 = new JSplitPane();
JSplitPane split2 = new JSplitPane();
JPanel panel1 = new JPanel()
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
split1.setLeftComponent(panel1);
split1.setRightComponent(panel2);
split2.setLeftComponent(panel2);
split2.setRightComponent(panel3);
tabbed.addTab("1",split1);
tabbed.addTab("2",split2);
//------------------------//
Unfortunately in split1 panel I cannot see panel2 but only panel1. In
split2 panel it all works fine. Why it doesn't work?
--
Lukasz Huculak
email***@***.com
|
|
|