Posts

JFrame & JLable

 Code : -  // 1 - JFrame // 2 - JLabel // 3 - FlowLayout - basic JLabel background = new JLabel (); background . setLocation ( 150 , 150 ); background . setBackground ( Color . black ); background . setOpaque ( true ); background . setSize ( 250 , 250 ); JLabel heading = new JLabel ( "Details" ); // YOu can also use setText function for set Text heading . setForeground ( Color . black ); // Change the Text Color heading . setBackground ( Color . white ); heading . setOpaque ( true ); heading . setHorizontalAlignment ( JLabel . CENTER ); //heading.setText(); heading . setSize ( 250 , 40 );   //----------------------Name------------------- JLabel name = new JLabel (); name . setBackground ( Color . white ); name . setOpaque ( true ); name . setForeground ( Color . black ); name . setText ( "Name" ); name . setSize ( 50 , 20 ); name . setLocation ( 20 , 60 ); // Set Margin name . setHorizontalAlignment...

JFrame

How to use JFrame in java  Code : --  public class frame { public static void main ( String [] args ) { ImageIcon imageIcon = new ImageIcon ( "image2.jpeg" ); JFrame jFrame = new JFrame (); // Calling Class jFrame . setBounds ( 100 , 100 , 250 , 250 ); //jFrame.setSize(250,250); // Set Size of JFrame jFrame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ); // For Exit jFrame . setLayout ( null ); //jFrame.setResizable(false); // For Resize of JFrame jFrame . setTitle ( "MyFrame" ); // SEt Title jFrame . setVisible ( true ); // For Showing jFrame . setIconImage ( imageIcon . getImage ()); //JFrame is a top-level container that provides a window on the screen //JFrame j =new JFrame(); //j.setSize(250,250); //j.setVisible(true); } }

How to use MouseListener in java

 Code = > import javax.swing. *; import javax.swing.border. Border ; import javax.swing.border.LineBorder ; import java.awt. *; import java.awt.event.MouseEvent ; import java.awt.event. MouseListener ; // Create a class and extend JFrame // Second Step - implement MouseListener interface // Third Step - create an component - Square = I am using with help of JLabel // We add more thing - for see location we add something public class simple extends JFrame implements MouseListener { // Create Constructor JLabel label ; JLabel label1 ; Border border ; simple (){ // Create JFrame this . setSize ( 400 , 400 ); // JFrame Size this . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ); // For Closing JFrame by Click Cross button //-----------We Add Border into frame for more good looking------ border = new LineBorder ( Color . black , 2 ); // calling Border instance and set Color with size; //----------JLabel------------- ...

Printing Pattern With Java

  public static final String color_black = " \u001B [30m" ; public static final String reset = " \u001B [0m" ; int row = 11 ; int col = 15 ; int row_mid = row / 2 ; String [][] arr = new String [ row ][ col ]; for ( int i = 0 ; i < row ; i ++){ arr [ i ][ 0 ]= "****" ; } int j = 2 ; for ( int i = row_mid - 1 ; i >= 0 ; i --){ if ( j < col ){ arr [ i ][ j ]= "****" ; j = j + 3 ; } } int k = 2 ; for ( int i = row_mid + 1 ; i < row ; i ++){ if ( k < col ){ arr [ i ][ k ]= "****" ; k = k + 3 ; } } arr [ 5 ][ 3 ]= "*" ; int count = 6 ; while ( count <= 7 ){ for ( int i = 0 ; i < row ; i ++){ for ( int l = 0 ; l < col ; l ++){ if ( arr [ i ][ l ]== null ){ System . out . print ( color_black + "*" + reset ); } else { String str = " \u001B [9...

#Pattern with #java // How to print Pattern

public static final String color_black = " \u001B [30m" ; public static final String color_yellow = " \u001B [93m" ; public static final String color_blue = " \u001B [96m" ; public static final String reset = " \u001B [0m" ;   Patter One => int count = 0 ; for ( int i = 1 ; i <= 10 ; i ++){ for ( int j = i ; j <= 10 ; j ++){ System . out . print ( " " ); } for ( int j = 1 ; j <= i ; j ++){ if ( i % 2 == 0 ){ String str = " \u001B [3" + count + "m" + j + " " ; System . out . print ( str ); } else { System . out . print ( j + " " ); } } count ++; for ( int j = i ; j <= 10 ; j ++){ System . out . print ( " " ); } System . out . println (); }      Pattern Two => for ( int i = 0 ; i <= 10 ; i ++){ for ( int j = i ; j...

Text Color Change in Console

Image
Text  Color Change in Console => public static final String ANSI_RESET = " \u001B [0m" ; public static final String yellow = " \u001B [91m" ; public static final String ANSI_BLUE = " \u001B [96m" ; public static final String ANSI_WHITE = " \u001B [38m" ; public static final String ANSI_BLACK = " \u001B [30m" ; public static final String green = " \u001B [92m" ;     " \u001B [93m"            93 -- FG Code                                                      

Printing " F "using for Loop = = >

Image
class alphabet{ public static void main(String[] args) {         int row=12;         int col=26;         String[][]arr=new String[row][col];         arr[0][0]="*";         arr[1][col-1]="|";         arr[6][14]="|";         for (int i=1; i<row; i++){             arr[i][0]="|";         }         for (int i=1; i<col; i++){             if (i==col-1){                 arr[0][i]="*";             }        ...