Monday, March 26, 2007

Eyesight Requirements Marines

JTable

This exercise in numbers on a java divide to get
the number of digits that has an integer.

For example if you enter the number 3454
the program will return a 4.

 
import java.io. *;

class {

Figures static int total = 0;
static int x = 0;
numCifras
static int (int x) {
while (x! = 0) {x = x/10
;
total + = 1; / / increment the counter

} return total;


} public static void main (String [] args) throws IOException {
/ / BufferedReader for reading from console
BufferedReader read = new BufferedReader (new InputStreamReader (System.in));
System.out . println ("Enter a nu4mero:");
/ / read a line like string
leer.readLine String line = ();
/ * Convertirmos the string to a number.
* You could put a try and catch to see with convertirlo.Por errors
* example if you enter a string * /
x = Integer.parseInt (line);
System.out.println ("The number of digits is:");
/ / Print the number of lines
System.out.println (numCifras (x));
}}

My Legs Ache/burn At Night

Search

JProgressBar Progress bars and graphics applications

This example looks for matches in files from a directory specified by the user
.

Problem:
If we have an application that performs a process that consumes a relatively long time, it's good to know the user of the application that the task is being processed and more or less the time left, so typical of the message: 'The process is by 20%' for example.

The Java Swing libraries, has mechanisms to show this progress, we will make an example of an application that searches a text string in all files in a directory espedificado.

Original source: telepolis.com
 
java.awt.GridLayout import, import
java.awt.Cursor;
import java.awt.event .*;
import java.util .*;
import java. io .*;
import javax.swing .*;
import java.lang.reflect.InvocationTargetException; ProgressDemo public class String {

startdir / / search directory
String patt, / / \u200b\u200bso let's look
outarea JTextArea / / output area for file pathnames
JFrame frame / / frame
JProgressBar Progbear / / progress bar
fileslab JLabel / / number of files
found search_flag boolean / / true if the search is in progress


class Search extends Thread {

/ / update the GUI
void doupdate (Runnable r) {try {

SwingUtilities.invokeAndWait (r);}

catch (InvocationTargetException e1) {
System.err.println (e1);

} catch (InterruptedException e2) {
System.err.println (e2);

}}
/ / gives us the list of files void
getFileList directory (File f, List list) {

/ / recursion if a directory within the same
if (f.isDirectory ()) {
String entries [] = f.list ();
for ( int i = 0; i < entries.length; i++) {
getFileList (new File (f, entries [i])
list);}



} / / for fciheros be added to the list and updates the progress bar
else if (f.isFile ()) {list.add
(f.getPath ());
final int size = list.size ();
if (size% 100! = 0) {
return;}

doupdate (new Runnable () {
public void run () {
progbar.setValue (size% 1000 )

}});}



} / / check that the file contains the string
fileMatch boolean (String fn, String patt) {boolean found = false
;


try {FileReader fr = new FileReader (fn) ;
BufferedReader br = new BufferedReader (fr);
String str;
while ((str = br.readLine ())! = null) {
if (str.indexOf (patt)! = -1) {found =
true;
break;

}}
br.close ();

} catch (IOException e) {
System.err.println (e);}

return found;}




/ / perform the search
public void run () {
List filelist = new ArrayList ();

final String sep = System.getProperty ("line.separator");

doupdate (new Runnable () {public void
run () {
outarea.setText
fileslab.setText ("");}

("");});

/ / gives us the list of all files and displays the counter
getFileList (new File ( startdir), filelist);
filelist.size final int size = ();
doupdate (new Runnable () {
public void run () {
progbar.setValue (0);
fileslab.setText ("Found" + size +
"files, searching ...");

}});

/ / set the progress monitor final
ProgressMonitor pm = new ProgressMonitor (
frame, "Searching for files", "", 0, size - 1);
pm.setMillisToDecideToPopup (0);
pm . setMillisToPopup (0);

/ / iterate between the files, updating the progress monitor
for (int i = 0; i < size; i++) {
final String fn = (String) filelist.get (i);
final int curr = i ;
if (pm.isCanceled ()) {
break;
}
final boolean b = fileMatch(fn, patt);
doUpdate(new Runnable() {
public void run() {
pm.setProgress(curr);
pm.setNote(fn);
if (b) {
outarea.append(fn + sep);
}
}
});
}

doUpdate(new Runnable() {
public void run() {
pm.close();
outarea.setCaretPosition(0);
fileslab.setText("");
}
});
search_flag = false;
}
}

public ProgressDemo() {
frame = new JFrame("ProgressDemo");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});



JPanel paneltop = new JPanel ();
panelbot JPanel = new JPanel ();
paneltop.setLayout (new GridLayout (5, 1));
JPanel panel1 = new JPanel ();
panel1.add (new JLabel ("Home Directory")) ; final
dirfield = new JTextField JTextField (20);
panel1.add (dirfield)
panel2 JPanel = new JPanel ();
panel2.add (new JLabel ("Search Pattern"));
pattfield = final JTextField new JTextField (20);
panel2.add (pattfield)
panel3 JPanel = new JPanel ();
JButton button = new JButton ("Search");
panel3.add(button);
JPanel panel4 = new JPanel();
progbar = new JProgressBar(0, 999);
panel4.add(progbar);
JPanel panel5 = new JPanel();
fileslab = new JLabel();
panel5.add(fileslab);
JPanel panel6 = new JPanel();
outarea = new JTextArea(8, 40);
outarea.setEditable(false);
JScrollPane jsp = new JScrollPane(outarea,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel6.add(jsp);

button.addActionListener (new ActionListener () {public void
actionPerformed (ActionEvent e) {startdir = dirfield.getText
();
pattfield.getText patt = ();
if (startdir == null else if (search_flag) {JOptionPane.showMessageDialog
(
frame, "Search in progress,"
"Error", JOptionPane.ERROR_MESSAGE)

} else {
search_flag = true;
new Search (). start ();

}}}
)

paneltop.add (panel1);
paneltop.add (panel2)
paneltop.add (panel3)
paneltop.add (panel4)
paneltop.add (panel5)
panelbot.add (panel6)
JPanel panel = new JPanel ();
panel.setLayout (new GridLayout (2, 1));
panel.add (paneltop)
panel.add (panelbot)
frame. getContentPane (). add (panel);
frame.pack ();
frame.setLocation (200, 200);
frame.setVisible (true);


} public static void main (String args []) {
ProgressDemo new ();
}}





Thursday, March 15, 2007

Most Common Numbers Of Pick 3

java files

The GridLayout is a way of placing the components with great flexibility in the panel.
with setLayout (new GridLayout (row, column)); can set a layout with the number of rows and columns and components are added in defined cells.

The following example places the components in a grid that occupies the entire frame and places four buttons in their respective cell.


class Example extends JFrame {JButton
a = new JButton ("one");
two = new JButton JButton ("two");
 JButton three = new JButton ("three"); 
JButton four = new JButton ("four");

Menu () {
this.setLayout (new GridLayout (2,2));
add (one);
add (two);
add (three);
add (four);

setTitle ("GridLayout Example");
setSize (400.400);
setVisible (true);}


public static void main (String [] args) {
new Example ();
}}






Tuesday, March 13, 2007

Folicure While Pregnant

FlowLayout GridLayout

The FlowLayout is the simplest method of placing the components inside a Panel or JPanel in java. Each of the components of a panel found in FlowLayout are located from left to right as in a list, one after the other, jumping down when there is no space enough for that component. FlowLayout

belonging to java.awt, but also can be applied to swing, such as in this case to a JPanel.

An example of the use of the FlowLayout in a program to place three buttons on a panel. import javax.swing .*;
import java.awt .*;


class Example extends JFrame {
JButton first = new JButton ("First");
JButton previous = new JButton ("Previous") ;
 JButton next = new JButton ("Next"); 
JButton last = new JButton ("Last");

Example () {
/ / Add the format to FlowLayout This.setLayout
JFrame (new FlowLayout ());
/ / Add components add
(first);
add (above);
add (next);
add (last)

setTitle ("FlowLayout Example") ;
setSize (400.400);
setVisible (true);


} public static void main (String [] args) {
new Example ();
}}






Monday, March 12, 2007

Infiniti Money On Poptropica

Add scrolling JTextArea in java

With this code you can insert scroll bars in a JTextArea as any text editor. Sea

Text zonaText a JTextArea and a JPanel which is inserted the text box example how to insert scrolling in a text box is as follows.

Code: JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)
zonaText.add (textScroll)


Saturday, March 3, 2007

Tiffany Granath Husband And Son



ejmplo the use of a JToolBar. Place a toolbar in your java programs. You usually add a ImageIcon (icon) representing the action the button.

For example to insert an image on the Save button use:
ImagenGuardar = new ImageIcon ImageIcon ("guardar.gif");
BGuardar.setIcon(ImagenGuardar);
import javax.swing.*;

class Menu extends JFrame {
//Toolbar
JToolBar TBarra=new JToolBar();
JButton BNuevo=new JButton("N");
JButton BAbrir=new JButton("A");
   JButton BCopiar=new JButton("C"); 
JButton BCortar=new JButton("C");
JButton BPegar=new JButton("P");
JButton BGuardar=new JButton("G");
public Menu() {

//ToolBar
TBarra.add(BNuevo);
TBarra.add(BAbrir);
TBarra.add(BGuardar);
TBarra.addSeparator();
TBarra.add(BCopiar);
TBarra.add (BCortar)
TBarra.add (SGA);
BGuardar.setToolTipText ("Save");
BNuevo.setToolTipText ("New");
BAbrir.setToolTipText ("Open");
BCopiar.setToolTipText (copy);
BCortar.setToolTipText (BCortar ");
BPegar.setToolTipText (" Paste ");


add (TBarra," North ");

TBarra.setFloatable (false);
setTitle ( "Examples JPopupMenu");
setSize (800.600);
setVisible (true);}


public static void main (String [] args) {
new Menu ();}




}


JPopupMenu

Friday, March 2, 2007

What Does The Number On Andy

JToolBar JPopupMenu, JMenu

Example of java. Added this code to a text box
a context menu with the right button with the basic command to copy, cut and paste
.

import javax.swing .*; / / Right button
PopUpMenu PopMenu = new JPopupMenu JPopupMenu ();
PopCortar = new JMenuItem JMenuItem ("Cut");
PopCopiar = new JMenuItem JMenuItem (copy);
 PopPegar = new JMenuItem JMenuItem ("Paste"); 
PopSelTodo = new JMenuItem JMenuItem ("Select All");
JTexttArea JTextArea text = new ();

public Menu () {

/ / JPopupMenu
PopMenu.add (PopCortar)
PopMenu.add (PopCopiar)
PopMenu.add (PopPegar)
add (text);
/ / set the JFrame
PopUpMenu Texto.setComponentPopupMenu (PopMenu)

setTitle ("Sample JPopupMenu");
setSize (800.600);
setVisible (true);


} public static void main (String [] args) {
new Menu ();
}}






Gall Stones And Leg Pain

right click in java

Example of creating a menu in java. This code performs a menu on Swing.
Remember that for the buttons to work you have to add an event of such action
action event: MGuardar.addActionListener (this);

import javax.swing .*; class Menu extends JFrame {
/ / Menu Items
mbars = new JMenuBar JMenuBar ();
Marchive = new JMenu JMenu ("File");
 MNuevo = new JMenuItem JMenuItem ("New"); 
Mabre = new JMenuItem JMenuItem ("Open");
MSAL = new JMenuItem JMenuItem ("Exit");
mGuard = new JMenuItem JMenuItem ("Save");
MImprimir = new JMenuItem JMenuItem ("Print");
JMenu Timing = new JMenu ("Edit");
MCortar = new JMenuItem JMenuItem ("Cut");
MCopiar = new JMenuItem JMenuItem ("Copy");
MPeg = new JMenuItem JMenuItem ("Paste");
JMenuItem MBuscar = new JMenuItem ("Search");
MRemplazar = new JMenuItem JMenuItem ("Replace");
mSELECT = new JMenuItem JMenuItem ("Select All");

public Menu () {
/ / Menu
MArchivo.add (MNuevo )
MArchivo.add (Mabre)
MArchivo.add (Health Ministry);
MArchivo.add (mGuard)
MArchivo.add (MImprimir)
MArchivo.addSeparator ();
MArchivo.add (Health Ministry);
MEdicion.add (MCortar)
MEdicion.add (MCopiar)
MEdicion.add (MPEG);

MEdicion.addSeparator () / / Puts a horizontal line of separation
MEdicion.add (MBuscar)
MEdicion.add (MRemplazar) Timing
. addSeparator ();
MEdicion.add (mSELECT)
MBarra.add (Marchive)
MBarra.add (measuring);
setJMenuBar (mbars)

setTitle ("java JMenu Example");
setSize (800.600);
setVisible (true);


} public static void main (String [] args) {
new Menu ();
}}






Thursday, March 1, 2007

Gold Leaf Flakes In Bottles

Search words

This code finds the number of occurrences of a word in a particular text string with the StringTokenizer class. Is case-sensitive.


/ / word: the word you wish to search in the text.
/ / TextoBusc: text which deesa look up the word. Void boolean uppercase = true;
numPalabras int = 0, / / \u200b\u200bCount the number and words in the text
 String token = ""; 
/ / Using StringTokenizer Class StringTokenizer
Search = new StringTokenizer (TextoBusc, "\\ "'!., \\ t \\ n ()[]?-_@");
while (Busca.hasMoreTokens ()! = false) {String
Busca.nextToken palabrilla = ();
if (shift) / / uppercase and lowercase Differentiating between
if (palabrilla.equals (word)) numPalabras + +;
else / / No dereference between uppercase and lowercase
if (palabrilla. toLowerCase (). equals (palabra.toLowerCase ())) numPalabras + +;
}}





Stopping Yaz Mid-cycle

Tokens

Most of the time you close the main window in java does not occur out of the application as can be expected. To exit completely from the application to close the window of your main form you must enter the following code in the main class of the form.



/ / Method to close the window addWindowListener (new WindowAdapter ()
System.exit (0);
}});