Showing posts with label symbol. Show all posts
Showing posts with label symbol. Show all posts

Square root symbol in java

After i spend a day to find how to print square root symbol in java through command prompt, someone tell me from java forum if our command prompt did not have a glyph for the square root character, this job will undone. But when i try use it in JOptionPane's message box it perform well.

In java "\u221A" is refer to square root symbol. It is Unicode.You can try to visit link below for more details :
Click here

If you want to print square root symbol through your command prompt, you can try something like this. I hope your command prompt can support for this thing.


public class Test2
{
public static void main(String[]args)
{
System.out.println("\u221A");
}
}


If you want to put it in JOptionPane's message box (this is perform well in my computer), you can try this :


import javax.swing.JOptionPane;

public class Test2
{
public static void main(String[]args)
{
JOptionPane.showMessageDialog(null,"\u221A");
}
}

Set password symbol or echo character color for JPasswordField

Source code below will show you, how to set JPasswordField echo character color base on RGB. You can get RGB value for your color using "Color picker" at above.

***************************************************************************
COMPLETE SOURCE CODE FOR : SetJPasswordFieldEchoCharacterColor.java
***************************************************************************


import javax.swing.JPasswordField;
import javax.swing.JFrame;

import java.awt.Color;

public class SetJPasswordFieldEchoCharacterColor
{
public static void main(String[]args)
{
//Create password field with number of columns equal to 10
JPasswordField passwordField=new JPasswordField(10);

//Create JFrame with title ( Set JPasswordField echo character color )
JFrame frame=new JFrame("Set JPasswordField echo character color");

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above
//R=255
//G=0
//B=0
Color color=new Color(255,0,0);

//Set JPasswordField echo character color to color that you choose
passwordField.setForeground(color);

//Add JPasswordField into JFrame
frame.add(passwordField);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(500,65);

//Make JFrame visible
frame.setVisible(true);
}
}


***************************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************************

Set password symbol or echo character for JPasswordField

Source code below will show you, how to set symbol that will be use in password field that build using JPasswordField. It also called echo character.

***************************************************************************
COMPLETE SOURCE CODE FOR : SetPasswordSymbol.java
***************************************************************************


import javax.swing.JPasswordField;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class SetPasswordSymbol
{
public static void main(String[]args)
{
//Create a password field with number of columns equal to 10
JPasswordField passwordField=new JPasswordField(10);

//Set password symbol
//In my case i use *
//You can change for what you want.But make sure it is only one character
//This is because, method setEchoChar receive only one character
passwordField.setEchoChar('*');


//Create a JFrame with title ( Set Password Symbol )
JFrame frame=new JFrame("Set Password Symbol");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Add password field into JFrame
frame.add(passwordField);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size to :
//WIDTH : 300 pixels
//HEIGHT : 65 pixels
frame.setSize(300,65);

//Make JFrame visible. So we can see it
frame.setVisible(true);
}
}


***************************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************************

RELAXING NATURE VIDEO