 |
 |
Index ‹ java-programmer
|
- Previous
- 1
- Jon's many-language ray tracer> IMO the defining characteristic of "object-oriented" programming
> is structuring programs around autarkic "objects" that contact each
> other in some way, but which all decide "by themselves" how they react
> to that, in a black-box sort of manner.
My rule of thumb is that if it can handle the shapes example, then it's
an object oriented programming language. About as objective as any
other definition of what OOP means. The downside is that this puts
BrainF*ck into the OO PL camp. :-)
http://www.angelfire.com/tx4/cus/shapes/index.html
(Still mulling how to best do the example for Alice ML).
Chris Rathman.
- 3
- get the number of children of a given elementI want to get the number of children of a given element. Below is my
code attempt and
the xml sample file. The caller is getElementChildNumber("persons");,
I expect
to get 2. Since there are 2 children that are under persons element.
Any ideas??
/**
get the number of children of a given element
*/
public int getElementChildNumber(String elementName)
{
DocumentBuilderFactory dbf = null;
DocumentBuilder db = null;
Document doc = null;
try
{
dbf = DocumentBuilderFactory.newInstance();
db = dbf.newDocumentBuilder();
doc = db.parse(fileName);
NodeList nodelist = doc.getElementsByTagName(elementName);
return nodelist.getLength();
}
catch (Exception e)
{ e.printStackTrace();
}
return -1;
}
<?xml version="1.0" encoding="UTF-8"?>
<response>
<persons>
<person>
<name>Joe</name>
<age>10</age>
</person>
<person>
<name>Mark</name>
<age>30</age>
</person>
</persons>
</response>
- 4
- socket design issues?Hi
from
http://www.onjava.com/pub/a/onjava/2002/10/02/javanio.html?page=4
Author said "The JVM thread-management machinery is designed to handle
a few tens of threads, not hundreds or thousands", true?
If i have one jave server that need to serve 1 trillion connection,
in traditional thread per connection design, the java server will hang
because the numberious connection will eat up all the memory by create
too many thread. How can i set a count of max_number_of_connection?
For NIO, i don't think it can do it. Firstly, although you can tell
the selector stop select when the server is very busy, but don't select
doesn't mean no socket income. A million of client try to open a socket
to your server, it will bomb your ServerSocketChannel object. Am i
correct?
so what is the *BEST* solution, any idea?
thanks
from Peter
- 4
- Java Technology Concept MapThe Java Technology Concept Map 1.0 is an interactive diagram,
a web of linked terms, to show the relationships among and uses
of the Java technologies. You can use the Map to get an overview
of the Java landscape as well as learn more about the details of
its components.
Launch the Map here:
http://java.sun.com/developer/onlineTraining/new2java/javamap/intro.html?ssobm=ng
- 5
- JMS Socket/Proxy reuse problemHi,
I have challange related to JMS usage of sockets.
A JMS Client connect to a JMS Server over HTTPS through a proxy. My
understanding is that a socket is created between the JMS client and
proxy and another socket is created between the proxy and the remote
JMS Server for single JMS message. Is this correct?
The problem is that a huge number of JMS messages is supposed to be
forwarded from the JMS client to the JMS server each sec.
Is there a way to reuse sockets in this scenario? The JMS Client and
JMS Server will reside in two JVM's but there will be a firewall
between. If the firewall was removed and replaced by a VPN (with
socket layer encryption) would this solve the problem?
Thanks for any pointers!
Best regards,
Helge
- 5
- setPreferredSize... How to use it ?...newbieThe way I use it is when I place a component in a JScrollPane. If the
component is too large to be seen, then when you call setPreferredSize
and revalidate, scrollbars will appear so that you can see the area you
specified in the Dimension
- 5
- Thunerbird help... [not java related , but please help if you can!]Hi all...
I know this is not a java question, but after seeking help on the
Thunderbird newsgroup, I was not able to get an answer to my question.
So since i know there are a lot of smart people in this group, I thought
of asking here.
here is the link to my question on the Thunderbird forum, please read,
and offer your insight!
http://forums.mozillazine.org/viewtopic.php?t=334466
many thanks
- 8
- JTable, fireTableDataChanged, selectionI use fireTableDataChanged to notify my Jtable to update, but when my JTable
updated, the previous selected rows (could be multiple) are lost ...
I want to know how to do to keep these selections when refreshing JTable by
this way ?
thx a lot
- 8
- Array problem for beginnerHello all
I am studying Java and am an absolute beginner in programming. I have
a programming problem which I have almost completed but I cannot get
ot work properly. It is an array question. the program is to hold data
entered by the user then the user can ask the program to print on
screen the data entered.With my program, it only displays the last
data entered, even though I have instantiated an Array object of the
class. I tried to find what is missing but I cannot find the solution.
Any hints will be apreciated. Cheers.
Following is the driver class and object class in full:
//This program collects up to 10 descrptions and passwords.User can
// enter data ,which can be recalled by the program.
// Driver for SecretClass class which follows.
import java.io.*;
class Hard //Driver for SecretClass
{
public static void main(String [] args) throws IOException
{
//declare variables
String [] inDesc = new String[10];
String [] inPassWord = new String [10];
String [] checkPassWord = new String [10];
String [] newPassWord = new String [10];
int option = 0;
//create SecretClass object
SecretClass [] secret = new SecretClass[10];
//prompt for options
System.out.println("Keychain of Secrets");
System.out.println("=================");
System.out.println(" 1. Add a secret \n 2. Check a secret \n 3.
Display summary \n 4. Change a secret\n 5. Quit");
//create keyboard reader
BufferedReader stdin = new BufferedReader(new
InputStreamReader(System.in));
//Loop the array
for(int i = 0; i < secret.length; i ++)
{
secret[i] = new SecretClass();
do
{
option = Integer.parseInt(stdin.readLine());
//enter user info
if(option == 1)
{
System.out.print("Enter the description: ");
inDesc[i] = stdin.readLine();
secret[i].setDescription(inDesc[i]);
System.out.print("Enter the password: ");
inPassWord[i] = stdin.readLine();
secret[i].setSecret(inPassWord[i]);
}
//option 2 check password
if(option == 2)
{
System.out.print("Secrets\n=======\n");
System.out.println((i+1) + ". Description: "
+secret[i].getDescription());
System.out.print("What is the password: ");
checkPassWord[i] = stdin.readLine();
if(checkPassWord[i].equals(secret[i].getSecret()))
System.out.print("Correct\n\n");
else
System.out.print("Incorrect");
}
// option 3 check description
if (option == 3)
{
System.out.println((i+1) +". Description: "
+secret[i].getDescription());
}
// option 4 change password
if (option == 4)
{
System.out.println("Descriptions\n");
System.out.println("============");
System.out.println((i+1) + ".Description: " +
secret[i].getDescription());
System.out.print("What is the password for " +
secret[i].getDescription() + ": ");
checkPassWord[i] = stdin.readLine();
if(checkPassWord[i].equals(secret[i].getSecret()))
System.out.print("Correct\n");
System.out.print("Enter the new password: ");
newPassWord[i] = stdin.readLine();
secret[i].setSecret(newPassWord[i]);
}
// invalid entries
if(option < 1 || option > 5)
{
System.out.println("Invalid option. Try again");
}
secret[i].Menu(); // repeat menu
}while(option !=5);
}
}
}
// **************************END OF HARD CLASS
********************************
//SecretWord class: contains description string and secret string
class SecretClass
{
//class variables
private String description;
private String secret;
//default constructor
SecretClass()
{
description = "none";
secret = "none";
}
//full constructor
SecretClass(String description, String secret)
{
this.description = description;
this.secret = secret;
}
//mutators
public void setDescription(String description)
{
this.description = description;
}
public void setSecret(String secret)
{
this.secret = secret;
}
//accesors
public String getDescription()
{
return description;
}
public String getSecret()
{
return secret;
}
// method for displaying menu
public void Menu()
{
System.out.println("\n");
System.out.println("Keychain of Secrets");
System.out.println("=================");
System.out.println(" 1. Add a secret \n 2. Check a secret \n 3.
Display summary \n 4. Change a secret\n 5. Quit");
System.out.print("Choose an option: ");
}
}
// ********End of the SecretClass ***********
- 8
- Eclipse jboss toolsHi,
has been any efforts to ports jboss tools plugin for Eclipse?
It contains some parts written in C (i think having to do with GUI editors).
Using eclipse-devel 3.3.2 and jboss tools 2.1.1 (previously known as JBossIDE and
now commercially named as "Jboss developer studio).
Installing the jboss tools plugins from within eclipse, asis, results in a highly unstable eclipse
environment.
Any ideas?
--
Achilleas Mantzios
- 9
- Swing Threading issue?Hi,
My UI hangs whenever I m trying do something without threading. I'm
quite amatuer with threads and need help please.
How can i make my UI thread safe?
THANKS!
/**
*
* @author Ho Wai Kit
*/
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
public class Stratego extends JFrame implements ActionListener{
private static final int ROWS = 5;
private static final int COLUMNS = 5;
private final Card[][] cards = new Card[ROWS][COLUMNS];
private JPanel centerPnl, boardPnl, rightPnl;
private Client clientGame=null;
private Server serverGame=null;
private AIGame aiGame=null;
private Socket con;
boolean isStarted, isConnected, isClient, isServer;
private Card inHand, target;
private String otherHostname = "";
private JLabel statusLbl;
private JMenuItem menuItemNewGame;
private JMenuItem menuItemLoadFile;
private JMenuItem menuItemSave;
private JMenuItem menuItemSaveAs;
private JMenuItem menuItemConnect;
private JMenuItem menuItemCloseConnection;
private ConnectionManager conMan;
private GameLogic gl;
private Protocol protocol;
DataOutputStream output;
DataInputStream input;
private char[] pieces = {Card.FLAG, Card.BOMB, Card.BOMB,
Card.MARSHAL, Card.MINER, Card.CAPTAIN, Card.GENERAL, Card.CAPTAIN,
Card.GENERAL, Card.SPY};
/** Creates a new instance of Stratego */
public Stratego(){
super("Stratego");
initCenterPnl();
conMan = new ConnectionManager();
//menu bar
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu gameMenu = new JMenu("File");
JMenu settingsMenu = new JMenu("Network");
menuBar.add(gameMenu);
menuBar.add(settingsMenu);
menuItemNewGame = new JMenuItem("New game");
menuItemNewGame.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
playAIGame();
}
});
gameMenu.add(menuItemNewGame);
menuItemLoadFile = new JMenuItem("Load file...");
menuItemLoadFile.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
//if (isFileChanged())
// askForSaving();
JFileChooser fileChooser = new JFileChooser();
//fileChooser.setCurrentDirectory(new
java.io.File(fileChooserDir));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.resetChoosableFileFilters();
//fileChooser.addChoosableFileFilter(new
PGNFileFilter());
int choice = fileChooser.showOpenDialog(null);
if (choice == JFileChooser.APPROVE_OPTION) {
//loadFile(fileChooser.getSelectedFile());
//fileName =
fileChooser.getSelectedFile().getName();
//setTitle(TITLE + " - " + fileName);
//fileIsChanged = false;
}
}
});
gameMenu.add(menuItemLoadFile);
menuItemSave = new JMenuItem("Save");
menuItemSave.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
//if (fileName != null && fileName.length() > 0) {
// save(fileName, false);
//} else {
// saveAs();
// }
}
});
gameMenu.add(menuItemSave);
menuItemSaveAs = new JMenuItem("Save as...");
menuItemSaveAs.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
// saveAs();
}
});
gameMenu.add(menuItemSaveAs);
gameMenu.addSeparator();
JMenuItem item2 = new JMenuItem("Exit");
item2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
if (clientGame!=null||serverGame!=null) {
int choice =
JOptionPane.showConfirmDialog(null, "Are you
sure?", "Close connection?", JOptionPane.YES_NO_OPTION);
if (choice == JOptionPane.YES_OPTION) {
closeConnections();
} else
return;
}
System.exit(0);
}
});
gameMenu.add(item2);
JMenuItem serverSettingsItem = new JMenuItem("Host Game");
serverSettingsItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
playGameAsHost();
}
});
settingsMenu.add(serverSettingsItem);
menuItemConnect = new JMenuItem("Join Game");
menuItemConnect.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
String input = JOptionPane.showInputDialog(null,
"Connect to IP : ");
if(input.trim().equals("")||input==null){
JOptionPane.showMessageDialog(null, "No IP
specified", "Error", JOptionPane.ERROR_MESSAGE);
}else{
playGameAsClient(input);
}
}
});
settingsMenu.add(menuItemConnect);
menuItemCloseConnection = new JMenuItem("Close connection");
menuItemCloseConnection.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt)
{
int choice =
JOptionPane.showConfirmDialog(
null,
"Are you sure?",
"Close connection?",
JOptionPane.YES_NO_OPTION);
if (choice == JOptionPane.YES_OPTION) {
//boardConnector.closeConnection();
//connectionClosed();
}
}
});
settingsMenu.add(menuItemCloseConnection);
menuItemCloseConnection.setEnabled(false);
//end of menu
Container c = getContentPane();
c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
c.add(centerPnl, BorderLayout.CENTER);
}
public void initCenterPnl(){
centerPnl = new JPanel();
centerPnl.setLayout(new BoxLayout(centerPnl,
BoxLayout.X_AXIS));
boardPnl = new JPanel();
fillBoard();
boardPnl.setSize(450, 450);
boardPnl.setMinimumSize(new Dimension(450, 450));
boardPnl.setMaximumSize(new Dimension(450, 450));
initRightPnl();
centerPnl.add(boardPnl);
centerPnl.add(rightPnl);
}
public void initRightPnl(){
rightPnl = new JPanel();
statusLbl = new JLabel();
rightPnl.setBorder(BorderFactory.createTitledBorder("Game
Status"));
//rightPnl.setSize(100, 450);
rightPnl.add(statusLbl);
rightPnl.setMinimumSize(new Dimension(250, 450));
rightPnl.setMaximumSize(new Dimension(250, 450));
}
public void fillBoard(){
boardPnl.setLayout(new GridLayout(ROWS, COLUMNS, 1, 1));
boardPnl.setBorder(BorderFactory.createTitledBorder("Board"));
for(int i = 0; i < ROWS; i++)
{
for(int j = 0; j < COLUMNS; j++)
{
cards[i][j] = new Card(Card.GRASS, i, j);
cards[i][j].addActionListener(this);
cards[i][j].setXCoordinate(i);
cards[i][j].setYCoordinate(j);
boardPnl.add(cards[i][j]);
}
}
//initialise water
cards[2][2].setCardType(Card.WATER);
cards[2][2].drawImage(Card.WATER);
}
public void closeConnections(){
if(isServer&&isConnected){
conMan.allDone = true;
isServer = false;
}else if(isClient&&isConnected){
isServer = false;
}
try{
con.close();
}catch(Exception e){
e.printStackTrace();
}
isConnected = false;
}
public void playAIGame(){
newGameBoard();
aiGame = new AIGame(cards, this);
System.out.println("AI game started");
isStarted = true;
placeCards(cards, Card.RED_PLAYER);
}
public void playGameAsHost(){
try {
JDialog notify = new JDialog();
conMan.start();
JLabel notifyLbl = new JLabel("Listening for connection...
...\n", 0);
notify.setTitle("Server IP : "
+InetAddress.getLocalHost().getHostAddress());
notify.getContentPane().setLayout(new FlowLayout());
notify.getContentPane().add(notifyLbl);
notify.setLocation (400, 300);
notify.setSize (250, 90);
notify.setVisible(true);
//ServerSocket server = new
ServerSocket(ConnectionManager.PORT_NO,
ConnectionManager.MAX_CONNECTIONS);
while(true){
con = conMan.getConnection();
//con = server.accept();
if(con!=null){
notify.dispose();
break;
}
}
isServer = true;
isConnected = true;
//serverGame = new Server(this, con);
System.out.println("Hosting Game");
isStarted = true;
placeCards(cards, Card.RED_PLAYER);
//repaint();
protocol = new Protocol(con, this);
input = new DataInputStream(con.getInputStream());
output = new DataOutputStream(con.getOutputStream());
InputReader inReader = new InputReader(input, protocol);
inReader.start();
//gl = new GameLogic(this, protocol);
sendMessage("server cone");
//readInput();
}catch(Exception e){
e.printStackTrace();
}
}
public void playGameAsClient(String ip){
try{
con = new Socket(InetAddress.getByName(ip),
ConnectionManager.PORT_NO);
if(con.isConnected()){
isConnected = true;
isClient = true;
System.out.println("Joining game");
isStarted = true;
placeCards(cards, Card.BLUE_PLAYER);
//repaint();
//clientGame = new Client(this, con);
protocol = new Protocol(con, this);
//gl = new GameLogic(this, protocol);
input = new DataInputStream(con.getInputStream());
output = new DataOutputStream(con.getOutputStream());
//usage of thread to read data (works)
InputReader inReader = new InputReader(input,
protocol);
inReader.start();
//end
sendMessage(Protocol.ATTACK_NOTIFICATION);
//without implementing a thread(does not work)
//readInput();
}else{
JOptionPane.showMessageDialog(null, "Connection cannot
be established.\nServer might not be active.", "Error",
JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
e.printStackTrace();
}
}
//place the cards automatically(testing)
public void placeCards(Card[][] cards, String playerColor){
int k=0;
for(int i = 3; i < 5; i++){
for(int j = 0; j < COLUMNS; j++){
cards[i][j].setExposed(false);
cards[i][j].setOwn(true);
cards[i][j].setCardType(pieces[k]);
cards[i][j].setPlayerColor(playerColor);
cards[i][j].drawImage(pieces[k], playerColor, true,
false);
k++;
}
}
}
public void wonGame(){
if(aiGame!=null){
aiGame.killAI();
aiGame=null;
}
//clientGame=null;
//serverGame=null;
}
private void lostGame(){
}
public void newGameBoard(){
for(int i = 0; i < ROWS; i++){
for(int j = 0; j < COLUMNS; j++){
emptyField(cards[i][j], cards);
}
}
cards[2][2].setCardType(Card.WATER);
cards[2][2].drawImage(Card.WATER);
}
public void emptyField(Card inHand, Card[][] cards){
int x = inHand.getXCoordinate();
int y = inHand.getYCoordinate();
cards[x][y].setCardType(Card.GRASS);
cards[x][y].setExposed(false);
cards[x][y].setOwn(false);
cards[x][y].drawImage(Card.GRASS);
cards[x][y].setSelected(false);
cards[x][y].setPlayerColor(Card.NULL_PLAYER);
}
public void sendMessageToLbl(String msg){
statusLbl.setText(msg);
}
public void actionPerformed(ActionEvent e){
Card card = null;
if(isStarted){
card = (Card)e.getSource();
if(aiGame!=null){
if(card.getCardType()!=Card.WATER){
if((inHand==null||inHand==card)&&card.isOwn()){
if(card.getCardType()!=Card.BOMB&&card.getCardType()!=Card.FLAG){
inHand = aiGame.selectCard(card, cards);
}
}else{
target=card;
if(aiGame.move(inHand, target, cards)){
inHand=null;
target=null;
}
}
}
}else if(isConnected){
if(card.getCardType()!=Card.WATER){
if((inHand==null||inHand==card)&&card.isOwn()){
if(card.getCardType()!=Card.BOMB&&card.getCardType()!=Card.FLAG){
inHand = gl.selectCard(card, cards);
}
}else{
target=card;
if(gl.move(inHand, target, cards,
Card.BLUE_PLAYER)){
inHand=null;
target=null;
}else{
JOptionPane.showMessageDialog(null, "You cannot
move back and forth between two tiles for three consecutive
turns!\nPlease try again.", "Invalid move", JOptionPane.ERROR_MESSAGE);
}
}
}
}
}
repaint();
}
public void paint(Graphics g){
super.paint(g);
}
public static void main(String args[]) {
JFrame.setDefaultLookAndFeelDecorated(true);
Stratego t = new Stratego();
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){
}
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t.setSize(600, 500);
//t.setResizable(false);
t.setVisible(true);
}
public void sendMessage(String msg){
try{
output.writeUTF(msg);
output.flush();
}catch(Exception e){
e.printStackTrace();
}
}
public void readInput(){
while(true){
String msg="";
try{
msg = input.readUTF();
}catch(Exception e){
}
if(msg!=null&&!msg.equals("")){
System.out.println(msg);
protocol.handleInput(msg);
msg="";
}
}
}
}
- 9
- 10
- sending java object from applet to a servlet containerHi,
I've been developing a web application which makes use of java applet
too. What I need to do is to send a serialized java object from applet
to a servlet container, get the necessary data from this object to be
used in a jsp. Imagine a situation that a user click on a button on
the applet, and a report will be generated in a jsp. Is it possible?
All your help is highly apreciated ;-))
Thanks
- 13
- 13
- "cannot find CactusTask" errorHello:
I am attempting to use the <cactifywar> and <cactus > tasks in an Ant
build file. I have set up <taskdef> element to point to all the
necessary jar files, including cactus-ant-1.6.1.jar as below:
<taskdef resource="cactus.tasks">
<path>
<pathelement location="${lib}/cactus-ant-1.6.1.jar"/>
and so on and so on.
</path>
</taskdef>
The CactusTask class is inside cactus-ant-1.6.1.jar but upon execution
I received the following error:
"cannot find org.apache.cactus.integration.ant.CactusTask"
Well, Ant must have found "cactus.tasks" inside cactus-ant-1.6.1.jar
or else it wouldn't have known the classname in the error message!
Now . . . junit.jar is also on my classpath. Is there a difference
between the junit.jar that comes with Cactus and the jar named
ant-junit.jar that comes with Ant? I put both in my classpath but to
no avail.
Help!
Eric Hamacher
email***@***.com
Madison, Wisconsin
|
| Author |
Message |
Roedy Green

|
Posted: 2005-11-20 5:25:00 |
Top |
java-programmer, A Pixel Matching Problem
this problem is like a miniature OCR problem.
Let's say you have some images that contain text, or screen snapshots
obtained by the Robot class. How can you extract the text from them?
You have the advantage that you probably have access to the fonts used
to create the text.
How might you go about creating an OCR for images? I was thinking of
writing this up as a student project.
The advantage you have over true OCR is all matches will be exact.
The complications are a variety of colours for foreground/background,
antialiasing and painting over muticoloured backgrounds. For JPGs you
may not have the fonts used. The edges of the text may be tweaked in
various ways, e.g. 3D, blurred, warped.
I thought you might proceed like this:
1. find rectangular regions containing only two colours.
2. draw an e in 10 font sizes for each font as your search templates.
3. look for a hole the right shape. When you find one, check all the
e's you have with that size/shape hole to see if you have a match on
the entire letter, check the whole rectangle.
4. if you have a match, calculate the baseline and starting point. now
draw a template ea in that same font and compare. If it fails try eb
etc. Work your way both left and right pulling that line.
You might construct a hashMap indexed by a digest of the glyph so you
can more rapidly check for matches. Your digest algorithm might trim
the glyph top/bottom/left/right so you don't need the stringWidth
information by actually drawing the character pair.
5. You carve the rectangle out of the bigger one, and break the
remaining into rectangles.
6. repeat until there are no more rectangles.
7. export the text each labelled with x.y where it was found.
8. In another program allow the user to highlight text, e.g. a column
or box to determine the linear order of the text desired.
Potential uses for such software include:
1. capturing filenames, error messages, crash locations that were
displayed in a non-cut/pasteable way.
2. by people trying to defeat my email munger. See
http://mindprod.com/applets/masker.html
3. by blind people extracting textual information from images.
4. To allow you to copy from any Swing Component.
5. to extract information from a screen snapshot without having to
retype it.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- jdbc commit issueHi,
I'm facing some problems with the JDBC connection commit.
I'm using an Oracle8i client and server.
The jdbc library is classes12.jar
My application uses eclipse3.1 as an IDE and the jdk version is
jdk1.5.0_01
The flow of logic is such that I acquire 2 to 3 connections to my
database repository. On each of these connections some update/insert
statements
are executed (through jdbc PrepareStatement->executeUpdate())
After the update statements I issue a connection.commit() on each of
the connections where update statements are fired.
I have noticed sometimes that although connection.commit has been
issued, my DB does not have any data.
If anyone has any clue to this please let me know.
Thanks for your time.
Arti
- 2
- java script problems XP dpreview and other sitesMainly on the popular digital photo site dpreview.com but
unfortunately not restricted to this site I sooner or later run into
the problem that the site navigation and posting does not work any
more: Normally a list of available sub items is displayed on the left
side, when positioning the cursor on any a specific pull down pops up.
But every other week or so the site is displayed with an empty
background where the menu normaly is and therefore no further
navigation ist possible. I Opera I get the menus but when I click the
javascript enabled send button for posts nothing happens too.
I am running Windos XP Home with all current updates with Norton
Internet Security 2002 and Norton System Works 2002. Even after a
clean reinstall of all apps with all updates I don't get a stable
system. My only rescue so far is to load a system partion image of a
good status some weeks ago. But as I said, this does not last for
long.
I tried reinstalling Windows Script 5.6, but it did not help.
Albert
- 3
- Array List IssueI have been having this unique issue with Array List I am trying add
say about 10 Objects in an Array List and conevr that to an Array.
Later when I parse through the Array i am having an Array of length 10
however i am only having the same element for all the 10 of them. can
anyone out there throw some light onto what i am doing wrong here here
is the peice of Code I am using
Course course = null;
for(int i=0;i<10;i++){
course = new Course();
course.setCourseName( "Course ".concat(Integer.toString(i)));
aList.add(course);
System.out.println(course.getCourseName());
}
Course[] courses = (Course[]) aList.toArray(new Course[0]);
Thanks
Sri
- 4
- awt default toolkitThe following will not show the image nor will it throw any exceptions. Not
throwing exceptions doesn't surprise me because the documentation show that
it won't. That is a little surprising in itself. I am not using Swing
components.
public void paint(Graphics g){
String fileName = "dir/a.gif";
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image img = toolkit.getImage(fileName);
// an awt panel's Graphics context doesnot show the image
g.drawImage(img, 0,0, null);
//this works fine
g.drawString("aString",50,50);
}
thanks, mike
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
- 5
- javax.mail truncated urlHi!
I use javax.mail to send http mails that include urls. On some mail
clients, including Lotus iNotes, urls contained in the mail are
truncated. For example:
http://www.crappysite.com/index.html?param1=foo¶m2=bar
becomes
http://www.crappysite.com/index.html?param1
Encoding in the email is set to "quoted-printable". I tried to set it
to "base64" but it didn't resolve the problem.
Thanks!
Alex
- 6
- HTTP creepIf you look at the packet headers going back and forth to your HTTP
server, you will discover a HECK of a lot of blather that really is
not doing much.
It is made worse by it all being human readable without abbreviations.
Add this overhead up on all packet headers being transferred each day
and you see a stupendous waste of bandwidth.
HTTP should be put on a diet, with rigid defaults, bitfield headers,
and compressed messages.
The original protocol was designed for maximum flexibility. Now we
have some experience, we can tighten it up.
It matters now that you have tiny handhelds trying to surf the net
over limited bandwidth.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
- 7
- Using wildcard character in web.xml in Tomcat 5I am trying to achieve the following:
<url-pattern>/a*</urlpattern> then go into servlet A. This would
include /a, /aa, /abc/123 etc.
I notice that servlet 2.4 doesn't treat * as a wildcard character in
this case. Therefore, servlet A would only be called if the URL is
exactly /a*.
I need to create this pattern for all characters and numbers except
when the path starts with '/_'. Therefore, I can not use a '/*'
notation. Can anyone suggest a workaround to this issue?
Thanks,
TC
- 8
- _scripting engines for java applications_Hi All,
I've written java app with classes that strickly corresponds to user's
business domain. Now I want to add scripting feature to my program to
enable user to create own scenarios of processing objects of those
business classes. Where to start? Is there any scripting languages
implemented in java?
thanks,
Andrey
- 9
- Java Printing API and Tobit FaxWareThis example for the Java Printing API
http://java.sun.com/products/java-media/2D/forDevelopers/sdk12print.html#printable
creates different output in Suns JRE 1.4 and 1.5 (tested with Windows
2000). This can be easily checked using the 'print to file' option.
The different behaviour of the new 1.5 JRE is causing problems with the
Tobit FaxWare printer driver.
Tobit FaxWare detects special command strings in the document, which
start with @@, followed by a command name and optionally a space
character ($20, #32) and a character, finally @@ again. For example, the
receiver fax number is encoded as @@NUMMER +4996421@@. If a document is
printed on the FaxWare printer driver using JRE 1.4, the document will
be sent as a Fax to this number.
In JRE 1.5 however, the printer output contains the character $a0 (#160)
instead of space, this is causing an error message in Tobit FaxWare.
I would like to find the reason for this change but could not find
information in the JRE 1.5 releasenotes
(http://java.sun.com/j2se/1.5.0/compatibility.html#incompatibilities),
is there another place where i could find informations about the
background of this change?
Many thanks in advance,
Michael
- 10
- SendMailServlet example & server setup ?I tried this example :
// import the JavaMail packages
import javax.mail.*;
import javax.mail.internet.*;
// import the servlet packages
import javax.servlet.*;
import javax.servlet.http.*;
// import misc classes that we need
import java.util.*;
import java.io.*;
public class SendMailServlet extends HttpServlet {
String smtpServer;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
// get the SMTP server from the servlet properties
smtpServer = config.getInitParameter("smtpServer");
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
// get the message parameters from the HTML page
String from = req.getParameter("from");
String to = req.getParameter("to");
String subject = req.getParameter("subject");
String text = req.getParameter("text");
PrintWriter out = res.getWriter();
res.setContentType("text/html");
try {
// set the SMTP host property value
Properties properties = System.getProperties();
properties.put("smtp.mail.yahoo.com", smtpServer);
// create a JavaMail session
Session session = Session.getInstance(properties, null);
// create a new MIME message
MimeMessage message = new MimeMessage(session);
// set the from address
Address fromAddress = new InternetAddress(from);
message.setFrom(fromAddress);
// set the to address
if (to != null) {
Address[] toAddress = InternetAddress.parse(to);
message.setRecipients(Message.RecipientType.TO, toAddress);
}
else
throw new MessagingException("No \"To\" address specified");
// set the subject
message.setSubject(subject);
// set the message body
message.setText(text);
// send the message
Transport.send(message);
out.println("Message sent successfully.");
}
catch (AddressException e) {
out.println("Invalid e-mail address.<br>" + e.getMessage());
}
catch (SendFailedException e) {
out.println("Send failed.<br>" + e.getMessage());
}
catch (MessagingException e) {
out.println("Unexpected error.<br>" + e.getMessage());
}
}
}
and got this:
type Exception report
message
description The server encountered an internal error () that prevented it
from fulfilling this request.
exception
java.lang.NullPointerException
java.util.Hashtable.put(Hashtable.java:396)
SendMailServlet.doPost(SendMailServlet.java:40)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
with : properties.put("smtp.mail.yahoo.com", smtpServer);in line
40.That is my first servlet so if you be so kind to give me a detailed
answer.
- 11
- Going to NMU jikes (C++ ABI update)
I'm notice on <URL:http://people.debian.org/~mfurr/gxx/rebuild.html>
that jikes need a rebuild due to the new C++ ABI. I asked on
#debian-java if anyone is working on that, but got no reply. It is a
build-dependency on 119 packages, so it is probably a good idea to do
it quickly. I plan to do the NMU myself shortly, so this is just an
warning email.
I only change debian/changelog, adding this entry:
jikes (1:1.22-2.1) unstable; urgency=low
* Non-maintainer upload to get a rebuild with the new C++ ABI.
-- Petter Reinholdtsen <email***@***.com> Fri, 22 Jul 2005 01:08:42 +0200
--
To UNSUBSCRIBE, email to email***@***.com
with a subject of "unsubscribe". Trouble? Contact email***@***.com
- 12
- socket & JVMThis is a multi-part message in MIME format.
Hi i'm trying to create a some sort of JAVA print server:
I've a machine that accept (throught a socket) some spool file........
Here's the JAVA code:
ServerSocket TServer;
int i = 0;
try{
TServer = new ServerSocket(TPort);
while( true ){
//frame.TModel.addElement("+++ WAITING REQUEST " + i );
Lpd_request request = new Lpd_request(TServer.accept(),frame,PQ,NumQueue);
request.start();
i = i + 1;
}
}
the problem is: every request launch another JVM for handle the print and create a pdf of the the spool data: for some reason if i create a batch that launch 5 spool file one after the other, the print server launch 5 thread, but some thread terminate not correctly.
In particular the exit code are 1-0-1-0-0 so the first fail, the second is executed and so on.....
Can I put a delay between thread execution for solve the problem???
Any suggestion????
--
---------------------------------------------
Mauro Anceschi
IT Department
Global Service Srl
Gruppo Motor Power Company Srl
www.motorpowergroup.com
Tel +39-0522-688189
Fax +39-0522-683552
IMPORTANT: This e-mail message is intended only for the named recipient(s) above and may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you have received this message in error, or are not the named recipient(s), please immediately notify the sender and delete this e-mail message.
--------------------------------------------
<!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 i'm trying to create a some sort of JAVA print
server:</FONT></DIV>
<DIV><FONT face=Arial size=2>I've a machine that accept (throught a socket) some
spool file........</FONT></DIV>
<DIV><FONT face=Arial size=2>Here's the JAVA code:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV>
<P><FONT face=Arial size=2>ServerSocket TServer;</FONT></P>
<P><FONT face=Arial size=2>int i = 0;</FONT></P>
<P><FONT face=Arial size=2>try</FONT><FONT face=Arial size=2>{</FONT></P>
<P><FONT face=Arial size=2> TServer = new
ServerSocket(TPort);</FONT></P>
<P><FONT face=Arial size=2> while( true )</FONT><FONT
face=Arial size=2>{</FONT></P>
<P><FONT face=Arial size=2>
//frame.TModel.addElement("+++ WAITING REQUEST " + i );</FONT></P>
<P><FONT face=Arial size=2> Lpd_request
request = new Lpd_request(TServer.accept(),frame,PQ,NumQueue);</FONT></P>
<P><FONT face=Arial size=2>
request.start();</FONT></P>
<P><FONT face=Arial size=2> i = i +
1;</FONT></P>
<P><FONT face=Arial size=2> }</FONT></P>
<P><FONT face=Arial size=2>}</FONT></P></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>the problem is: every request launch another JVM
for handle the print and create a pdf of the the spool data: for some reason if
i create a batch that launch 5 spool file one after the
other, the print server launch 5 thread, but some thread
terminate not correctly.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>In particular the exit code are 1-0-1-0-0 so the
first fail, the second is executed and so on.....</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Can I put a delay between thread execution for
solve the problem???</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Any suggestion????</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT><BR><FONT
face=Arial size=2>--
<BR>---------------------------------------------<BR> <BR>Mauro
Anceschi<BR>IT Department<BR> <BR>Global Service Srl<BR>Gruppo Motor Power
Company Srl<BR></FONT><A href="http://www.motorpowergroup.com"><FONT face=Arial
size=2>www.motorpowergroup.com</FONT></A><BR><FONT face=Arial size=2>Tel
+39-0522-688189<BR>Fax +39-0522-683552<BR> <BR> <BR>IMPORTANT: This
e-mail message is intended only for the named recipient(s) above and may contain
information that is privileged, confidential and/or exempt from disclosure under
applicable law. If you have received this message in error, or are not the named
recipient(s), please immediately notify the sender and delete this e-mail
message.<BR> --------------------------------------------</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>
- 13
- record numbersMaybe my question is stupid and wrong but I hope that you will understand.
So, image that you need to create web application which will used by many
peoples in one LAN. They processing some documents and every person has the
particular number of documents in particular order (1. person has documents
from 1 to 100, second from 101 to 200 etc), which process with the
particular number (first document -> number 1 in a database). If they all
work in a same time, what is the easiest and the most safety way to manage
that? Adding number manually is the logical solution but if 2 person put the
same number, can they freeze the database or databases are imune on that ?
- 14
- GridBag Layout queriesIt might appear long, but I think the answers will be of
just a few words describing the correct command/syntax.
After the Jbutton part has run successfully, the following
difficulties are coming in the next step.
- Individual buttons are not coming as same width. Whichever
button has more text or wider letters is coming wider, and
others are coming less wider.
- though left edge of a column of button is duly aligned,
the right edge is becoming zigzag due to the above.
- width of the largest button in a column is deciding the
width of the the entire column.
how to force all button to be of same width? If all buttons
in a column are of same width, the above are automatically
solved.
I am also finding that the three characters I have to
display are appearing in the centre, and there is huge space
left at the left and right of my text in the button.
Because of this, I have to unncessary keep my window wide so
that characters remain visible, otherwise several characters
are not becoming visible.
When I put setmargin I got this compile error.
setMargin(java.awt.Insets) in javax.swing.AbstractButton
cannot be applied to (int,int,int,int)
button[gridY1][gridX1].setMargin(0,0,0,0);
The best method would have been if we could have just given
a single width for all buttons, and it would have compressed
whatever text within that width.
- Even after giving gridwidth as 2 or 3, though the button
is reserving the width of those many columns, its width is
still that of a single button. the area next to it is coming
blank.
how to make it wider to fill the columns it is covering.
- Even after giving gridheight as 2, though the button is
reserving the height of those many rows, its height is still
of a single button. the area below it is coming blank.
how to make it taller to fill the rows it is covering.
ipadx or ipadx are not working. while trying to use
gridBagL.setConstraints(button, gridBagC);
it is giving error
setConstraints(java.awt.Component,java.awt.GridBagConstraints)
in java.awt.GridBagLayout cannot be applied to
(javax.swing.JButton[][],java.awt.GridBagConstraints)
what is the default height and width of a button?
in place of using an icon in setrolloverenabled(), can we
have some way to make it display whatever text is there in
the button, in a larger font size?
to set the horizontal alignment, if I am giving
button[gridY1][gridX1].setHorizontalAlignment(0);
it is still appearing at the centre. what are the options
for (int) are not shown in the tutorial.
Thanks.
-Rawat
- 15
- Fax QuestionHas anyone used 'RFax 1.0 - Java [TM] fax component' from
http://www.java4less.com/java_fax.htm?
Good or bad (other comments)?
thanks!
|
|
|