|
In other words change your for loops to
1. for (int i = 0; i < ar.length; i++)
2. for (int j = i+1; j < ar.length; j++)
Regards
|
|
|
|
|
I want that in textbox if 0 is insert than it shows an alert message. The textbox insert numbers only. How will I validate it? please help
thanx in advance.
|
|
|
|
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Validate extends JFrame
{
TextField t;
public Validate()
{
t= new TextField(10);
add(t);
t.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
int key = e.getKeyCode();
if ((key == KeyEvent.VK_0))
{
JOptionPane.showMessageDialog(null,"0 Was Clicked", "Note",JOptionPane.INFORMATION_MESSAGE);
}
else
if((key == KeyEvent.VK_1)||(key == KeyEvent.VK_2)||(key == KeyEvent.VK_3)||(key == KeyEvent.VK_4)||(key == KeyEvent.VK_5)||(key == KeyEvent.VK_6||(key == KeyEvent.VK_7)||(key == KeyEvent.VK_8)||(key == KeyEvent.VK_9)))
{
return;
}
else
{
JOptionPane.showMessageDialog(null,"Invalid Input", "Note",JOptionPane.WARNING_MESSAGE);
String s = t.getText();
t.setText(s.replaceAll(e.getKeyChar()+"",""));
}
}
}
);
setTitle("Validate");
setLocationRelativeTo(null);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args)
{
new Validate();
}
}
|
|
|
|
|
Would it not be simpler to use a JFormattedTextField to ensure numeric input and an InputVerifier to check the value is not 0?
|
|
|
|
|
True there are many ways to do it.
Snippet 1: Integers
public Validate()
{
Text.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!(Character.isDigit(c) ||(c == KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE)))
{
getToolkit().beep();
e.consume();
}
if( c == KeyEvent.VK_0)
{
Label.setText("0 entered");
Label.setForeground(Color.red);
}
else
{
Label.setText("ok");
Label.setForeground(Color.black);
}
}
});
Snippet 2: Double
public class Validate()
{
DoubleValidate dv = new DoubleValidate();
public Validate()
{
Text.setDocument(dv);
add(Text);
}
static class DoubleValidate extends PlainDocument
{
public void insertString(int offset,String string, AttributeSet attributes)throws BadLocationException
{
if (string == null)
{
return;
}
else
{
String newValue;
int length = getLength();
if (length == 0)
{
newValue = string;
}
else
{
String currentContent = getText(0, length);
StringBuffer currentBuffer = new StringBuffer(currentContent);
currentBuffer.insert(offset, string);
newValue = currentBuffer.toString();
}
try
{
Double.parseDouble(newValue);
super.insertString(offset, string,attributes);
}
catch (NumberFormatException exception)
{
Toolkit.getDefaultToolkit().beep();
}
}
}
}
}
|
|
|
|
|
Yes, there are many ways to make something more complicated than it needs to be.
|
|
|
|
|
I m trying to Run a blackbery Application on simulator using Jdk,jre and Eclipse The project but When i run Build.xml as Run as Ant then get some building errors like
Buildfile: E:\Current\BlackBerry Projects\4th\mfunds-java\build\build.xml
[typedef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
buildAndPackageTarget:
[typedef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
clean:
[delete] Deleting directory E:\Current\BlackBerry Projects\4th\mfunds-java\preprocessed\${alias}
[delete] Deleting directory E:\Current\BlackBerry Projects\4th\mfunds-java\classes\${alias}
[echo] Target ${alias} was cleaned
[typedef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
preprocess:
[mkdir] Created dir: E:\Current\BlackBerry Projects\4th\mfunds-java\preprocessed\${alias}
[wtkpreprocess] **************************************************************
[wtkpreprocess] * Antenna 1.0.1 initialized for project "telSPACE Java" *
[wtkpreprocess] * Using Sun Wireless Toolkit 2.5 (CLDC-1.0; MIDP-2.0) *
[wtkpreprocess] **************************************************************
[wtkpreprocess] Preprocessing 40 file(s) at E:\Current\BlackBerry Projects\4th\mfunds-java\src
[echo] Pre-processed successfuly with: ${platform}, ${platformver}, ${alias}, ${alias2}
[typedef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
compile:
[mkdir] Created dir: E:\Current\BlackBerry Projects\4th\mfunds-java\classes\${alias}
BUILD FAILED
E:\Current\BlackBerry Projects\4th\mfunds-java\build\build.xml:334: The following error occurred while executing this line:
E:\Current\BlackBerry Projects\4th\mfunds-java\build\build.xml:377: Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Total time: 18 seconds
please suggest some thing
|
|
|
|
|
Ok,
The problem lies in...
E:\Current\BlackBerry Projects\4th\mfunds-java\build\build.xml:377: Problem: failed to create task or type if
That error tells me you that...
Cause: The name is undefined.
and you should...
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
See? All that and all I did was read what your compiler shat out...
|
|
|
|
|
Please give me project in Java my platform is netbeans 5.5. or tell me some websites where i got projects. I want to try to make my project please help me.
thanx in advance.
|
|
|
|
|
You want someone to do what ? Send you a project ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I write a code for automatic ID generated. But If somebody deleted the Id for example I have three ID i.e. 001,002, 003. If somebody deleted 002 so when we add the id is generated 004 but I want the ID is generated 002. Please tell me
thanx in advance.
|
|
|
|
|
http://doc.ddart.net/mssql/sql70/dbcc_5.htm
Read about this
Extra resource
http://www.h2database.com/html/main.html This contains SQL grammar for most queries.
Regards
|
|
|
|
|
hello every1!!
i m making my final year project on video watermarking using SVD transform.
i wanted to know how to compute SVD of an image using JAMA...
Can u plz explain the sysntax for it..
Ankita..< >
|
|
|
|
|
http://andrewtrusty.com/math2605/2605project4.html
http://edbardsley.org/classes/15-211/lab4/lossy.html
These links will help
Regards
|
|
|
|
|
|
Let me know the features of jdk 1.6 and 1.7
and also latest versions of servelt/jsp
|
|
|
|
|
http://java.sun.com/javase/6/docs/
http://java.sun.com/javase/7/docs/index.html
Read These.
Regards
|
|
|
|
|
Okay, I have included my code below. I am supposed to have the user input a html file name (i got that part down) and then i'm supposed to look at the file and make two lists of words, one of words that are italicized between <i> </i> and one of words that are bold between <b> </b>. So I need to know how to do this. I think I should use a regular expression? Am I rite? regular expression looking for the <b> and </b> tag and creating anything in between as a string that I add to a string container. then i print the string container as output. is this okay? can you help me with the regular expression?
<pre>package final_project_2;
import java.io.*;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
try{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the name of the file: ");
String line = input.readLine();
FileInputStream in = null;
in = new FileInputStream(line);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null, "IOException: " + e.getMessage());
}
}
}</pre>
|
|
|
|
|
import java.io.File;
import java.util.*;
public class RegularExpression
{
public static void main(String[] args) throws Exception
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter HTML file Name:");
File HtmlFile = new File(scan.next());
Scanner scan2 = new Scanner(HtmlFile);
int FirstIndex =0,LastIndex =0;
ArrayList<String> Bold = new ArrayList<String>();
ArrayList<String> Italics = new ArrayList<String>();
while(scan2.hasNext())
{
String q = scan2.nextLine();
for (int i =0; i <q.length(); i++)
{
if (i+3<=q.length())
{
if (q.substring(i, i+3).equalsIgnoreCase("<b>"))
{
FirstIndex = i+3;
for (int j = FirstIndex; j <q.length(); j++)
{
if (j+4<=q.length())
{
if (q.substring(j, j+4).equalsIgnoreCase("</b>"))
{
LastIndex = j;
Bold.add(q.substring(FirstIndex,LastIndex));
break;
}
}
}
}
else
if (q.substring(i, i+3).equalsIgnoreCase("<i>"))
{
for (int j = FirstIndex; j <q.length(); j++)
{
if (j+4<=q.length())
{
if (q.substring(j, j+4).equalsIgnoreCase("</i>"))
{
LastIndex = j;
Italics.add(q.substring(FirstIndex,LastIndex));
break;
}
}
}
}
}
}
}
System.out.println("Bold:");
for (int i =0; i <Bold.size(); i++)
{
System.out.println(Bold.get(i));
}
System.out.println("Italics:");
for (int i =0; i <Bold.size(); i++)
{
System.out.println(Italics.get(i));
}
}
}
|
|
|
|
|
i need Java codings of Vernam Cipher Algorithm.can anybody help me plz.
|
|
|
|
|
Before all the cross-posting, did you even bother to read this or here?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
http://www.dreamincode.net/forums/showtopic32278.htm
Read this
Regards
|
|
|
|
|
Hello all,
i have created an application in java. it basically converts the script of a language from roman urdu to formal urdu script. i want to dock this application to msn messneger so that msn users (urdu speaking) can use this addon to convert there roman urdu into formal urdu script before sending it to the far end. the problem is, i dont know if there is any API for creating plugins for msn (or yahoo) , moreover if here is any i dont know if it will be compatible with java. i appriciate any form of help in this regard
will anyone please answer my question
thank you
regards
adeel
modified on Tuesday, September 1, 2009 3:03 PM
|
|
|
|
|
http://jml.blathersource.org
Try this API
Regards
|
|
|
|
|
Hi all,
thanks a lot for ur help. actually i had come across this library earlier i tried to use it because i could not find any tutorail on JML on their page. now when u referred to this library i decided to give it another try and went through the code. i have examined code in BasicMessenger.java and PrettyMessenger.java. i was able to grasp some of the code segments. when i execute this code with my hotmail id it dumps in lot of unnecessary information on the cosole plus it does not show complete contact list. can u please help me in this regard how to get useful information from my account or refer to any useful document about this library.
moreover i get an impression that this lib will enable me to mimic msn messenger's features in my java application rather than interacting with windows live messenger client that is installed on my machine. am i right in thinking so.
once again thanks a lot for ur considerate attention.
i really really mean it
regards
adeel
|
|
|
|