JAVA - How To Change A JTextField Font Color, Name, Style, And Size In Java

JAVA - How To Change A JTextField Font Color, Name, Style, And Size In Java

                                                                         


Source Code:


package JavaDB_001;

import java.awt.Color;

import java.awt.Font;

import javax.swing.*;



public class Project extends JFrame{
    public Project(){
    super("Change JTextField Font Name, Style, Size, Color");
    
    //"Verdana" = font name;
    //Font.BOLD = font style, You Can Also Put An Int;
    // 30 = size;
    Font f = new Font("Verdana",Font.BOLD,30);
    JTextField tf = new JTextField(60);
    //set the font to the JTextField
    tf.setFont(f);
    //change a JTextField font color
    tf.setForeground(Color.red);
    tf.setBounds(80,20,250,50);
    add(tf);
    setLayout(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    setSize(400,200);
    setVisible(true);
    }
    public static void main(String[] args){
        new Project();
    }
   }
///////////////////////OUTPUT:
                    
Jtextfield font color , name,size,style
 Jtextfield font color , name,size,style 
See Also In Jlabel



JAVA - How To Change A Jlabel Font Color, Name, Style, And Size In Java

JAVA - How To Change A Jlabel Font Color, Name, Style, And Size In Java

                                                                        

Source Code:

package JavaDB_001;
import java.awt.Color;
import java.awt.Font;
import javax.swing.*;

public class Project extends JFrame{
    JLabel label;
    public Project(){
    super("Change JLabel Font Name, Style, Size, Color");
    label = new JLabel("This Is My Text Here");

    //"TimesRoman" = font name;
    //Font.ITALIC = font style, You Can Also Put An Int;
    // 20 = size;

    Font f = new Font("TimesRoman",Font.BOLD,25);
    //change a jlabel font color
    label.setForeground(Color.red);
  //set the font to the Jlabel 
    label.setFont(f);
    label.setBounds(80,20,250,80);
    
    setLayout(null);
    add(label);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    setSize(400,200);
    setVisible(true);
    }
    public static void main(String[] args){
        new Project();

        //to know some font style number
        System.out.println(Font.BOLD);
        System.out.println(Font.CENTER_BASELINE);
        System.out.println(Font.HANGING_BASELINE);
        System.out.println(Font.ITALIC);
        System.out.println(Font.LAYOUT_LEFT_TO_RIGHT);
        System.out.println(Font.LAYOUT_NO_LIMIT_CONTEXT);
        System.out.println(Font.LAYOUT_NO_START_CONTEXT);
        System.out.println(Font.LAYOUT_RIGHT_TO_LEFT);
        System.out.println(Font.PLAIN);
        System.out.println(Font.ROMAN_BASELINE);
        System.out.println(Font.TRUETYPE_FONT);
        System.out.println(Font.TYPE1_FONT);
    }
   }
/////////////////////////OUTPUT:

Change A Jlabel Font Color, Name, Style, And Size In Java
Change A Jlabel Font Color, Name, Style, And Size In Java
1
1
2
2
0
4
2
1
0
0
0
1



JAVA - How To Use HashMap In Java With Iterator

JAVA - How To Use HashMap In Java With Iterator

                                                                                                                                                            
using hashmap with iterator in java


In this java Collection tutorial we will see How To Use A HashMap With Iterator In Java NetBeans

Source Code:

package JavaDB_001;
import java.util.*;


public class Work {
    public static void main(String[] args){
        //create a HashMap
        //Key is String 
        //value is Integer
       HashMap<String,Integer> employer = new HashMap<String,Integer>();
       
       //filling the HashMap with put method
       employer.put("employer 1", 34);
       employer.put("employer 2", 43);
       employer.put("employer 3", 36);
       employer.put("employer 5", 55);
       employer.put("employer 6", 29);
       employer.put("employer 7", 27);
       employer.put("employer 8", 30);
       employer.put("employer 9", 51);
       
       //displaying only the key of the hashmap
       System.out.println("_______Key_______");
         Iterator<String> itName = employer.keySet().iterator();
            while(itName.hasNext())
             System.out.println(itName.next());
       
       //displaying only the value of the hashmap
       System.out.println("_______Value_______");
        Iterator<Integer> itAge = employer.values().iterator();
          while(itAge.hasNext())
            System.out.println(itAge.next());
       
      //displaying the key and the value of the hashmap
       System.out.println("_______Key_And_Value_______");  
         Iterator<String> itname = employer.keySet().iterator();
            while(itname.hasNext()){
                String s = itname.next();
              System.out.println(itname.next()+" -*- "+employer.get(s));
           }
    }
       
}
///////////////////////////OUTPUT:
_______Key_______
employer 9
employer 5
employer 6
employer 7
employer 8
employer 1
employer 2
employer 3
_______Value_______
51
55
29
27
30
34
43
36
_______Key_And_Value_______
employer 9 -*- 51
employer 5 -*- 55
employer 6 -*- 29
employer 7 -*- 27
employer 8 -*- 30
employer 1 -*- 34
employer 2 -*- 43
employer 3 -*- 36


See Also: How To Use HashMap In Java



JAVA - How To Use HashMap In Java

JAVA - How To Use HashMap In Java NetBeans

                                                                                                                                                            
using hashmap in java


In this java Collection Code we will see How To Use A HashMap In Java NetBeans
With Some Java HashMap Example of Methodes.
1: how to create a HashMap 
2: how to dispaly data from it
3: how to remove an element

4: how to clear all elements from it
and more........

Source Code:

package JavaDB_001;
import java.util.*;


public class Work {
    public static void main(String[] args){
        //create a HashMap
        //Key is String 
        //value is Integer
       HashMap<String,Integer> employer = new HashMap<String,Integer>();
       
       //filling the HashMap with put method
       employer.put("employer 1", 34);
       employer.put("employer 2", 43);
       employer.put("employer 3", 36);
       employer.put("employer 5", 55);
       employer.put("employer 6", 29);
       employer.put("employer 7", 27);
       employer.put("employer 8", 30);
       employer.put("employer 9", 51);
       
       //displaying only the key of the hashmap
       Set<String> EmployerName = employer.keySet();
       System.out.println("_______Key_______");
       for(String s: EmployerName)
           System.out.println(s);
       
       //displaying only the value of the hashmap
       Collection<Integer> Age = employer.values();
       System.out.println("_______Value_______");
       for(Integer i : Age)
           System.out.println(i);
       
      //displaying the key and the value of the hashmap
       System.out.println("_______Key_And_Value_______");
      Set<String> EmpName = employer.keySet();
       for(String s: EmpName)
           System.out.println("Key => ["+s +"] Value => ["+employer.get(s)+"]");
    }
       
}
///////////////////////////OUTPUT:
_______Key_______
employer 9
employer 5
employer 6
employer 7
employer 8
employer 1
employer 2
employer 3
_______Value_______
51
55
29
27
30
34
43
36
_______Key_And_Value_______
Key => [employer 9] Value => [51]
Key => [employer 5] Value => [55]
Key => [employer 6] Value => [29]
Key => [employer 7] Value => [27]
Key => [employer 8] Value => [30]
Key => [employer 1] Value => [34]
Key => [employer 2] Value => [43]
Key => [employer 3] Value => [36]


Another Source Code:

package javaapp;

import java.util.ArrayList;
import java.util.HashMap;


public class Work {
    public static void main(String[] args){
        HashMap<Integer, String> map = new HashMap<Integer, String>();
        map.put(10, "A");
        map.put(20, "B");
        map.put(30, "C");
        map.put(40, "D");
        map.put(50, "E");
        map.put(60, "F");
        
        printData(map);
        
        // delete an elemnt from the hashmap
        map.remove(60);
        printData(map);
        System.out.println("");
        System.out.println(map);
        
        map.replace(10, "Z");
        System.out.println(map);
        
        // see if the map contains a value
        boolean statVal = map.containsValue("Z");
        System.out.println(statVal);
        
        // see if the map contains a key
        boolean statKey = map.containsKey(40);
        System.out.println(statKey);
        
        // get value using his key
        String val = map.get(100);
        System.out.println(val);
        
        // check if the map is empty
        boolean isEmpty = map.isEmpty();
        System.out.println(isEmpty);

        // insert tvalues from hashmap to arraylist
        ArrayList<String> values = new ArrayList<String>(map.values());
        System.out.println("Values: "+values); 
        
        // create another hashmap
        HashMap<Integer, String> map2 = new HashMap<Integer, String>();
        map2.put(100,"MAP2-1");
        map2.put(200,"MAP2-2");
        map2.put(300,"MAP2-3");
        
        // insert a map in another map
        map.putAll(map2);
        printData(map);
        
       // clone the hashmap 
       Object obj = map.clone();
       System.out.println(obj);
       
       /*
       If the specified key is not associated with a value
       or the value is null associates it with the given value 
       in this example the key is 111 and value is null
       */
       map.put(111, null);
       map.putIfAbsent(111, "NewValue");
       System.out.println(map);
       
        // get the HashMap Size
        int mapSize = map.size();
        System.out.println(mapSize);
        
        // clear all elements from the hashmap
        map.clear();
        mapSize = map.size();
        System.out.println(mapSize);
        System.out.println("The HashMap Is Clear: "+map);
        System.out.println("The HashMap is Empty Now = "+map.isEmpty());
        
    }
    
    // cretate a function to print data from the hashmap 
    public static void printData(HashMap<Integer,String> list){
        for(Integer i : list.keySet()){
            System.out.println("Key: "+i+" Value: "+list.get(i));
        }
        System.out.println("-----------------------");
    }
}

//OUTPUT:

Key: 50 Value: E
Key: 20 Value: B
Key: 40 Value: D
Key: 10 Value: A
Key: 60 Value: F
Key: 30 Value: C
-----------------------
Key: 50 Value: E
Key: 20 Value: B
Key: 40 Value: D
Key: 10 Value: A
Key: 30 Value: C
-----------------------

{50=E, 20=B, 40=D, 10=A, 30=C}
{50=E, 20=B, 40=D, 10=Z, 30=C}
true
true
null
false
Values: [E, B, D, Z, C]
Key: 50 Value: E
Key: 20 Value: B
Key: 100 Value: MAP2-1
Key: 40 Value: D
Key: 200 Value: MAP2-2
Key: 10 Value: Z
Key: 300 Value: MAP2-3
Key: 30 Value: C
-----------------------
{50=E, 20=B, 100=MAP2-1, 40=D, 200=MAP2-2, 10=Z, 300=MAP2-3, 30=C}
{50=E, 20=B, 100=MAP2-1, 40=D, 200=MAP2-2, 10=Z, 300=MAP2-3, 30=C, 111=NewValue}
9
0
The HashMap Is Clear: {}

The HashMap is Empty Now = true



See Also : HashMap In Java With Iterator



JAVA - How To Remove All Objects In An Arraylist That Exist In Another Arraylist

JAVA - How To Remove All Objects In An Arraylist That Exist In Another Arraylist

JAVA - How To Remove All Objects In An Arraylist If Exist In Another Arraylist

_________________________________________________________________________

In this java Collection Tutorial we will see How To Delete All Elements from ArrayList
If Elements Exist In Another ArrayList In Java NetBeans .

Source Code:

package javadb_001;
import java.util.ArrayList;
import java.util.List;
public class Learn {
    
public static void main(String[] args){
    String[] str1 = {"C#","JAVA","Android","ASP.NET","J2EE","PHP"};
 List<String> list = new ArrayList<String>(); 
 //fill the list
 for(String s1 : str1){
     list.add(s1);
     }
     String[] str2 = {"C","C++","JAVA","DELPHY","HTML","CSS","C#"};
     List<String> list2 = new ArrayList<String>();
     
     //fill the list2
     for(String s2 : str2){
         list2.add(s2);
     }
     
    //display the list2 Objects before removing existing objects
     for(String s : list2){
         System.out.println(s);
     }
      System.out.println("____________________");
      
     for(int i = 0; i < list.size(); i++){
         for(int j = 0; j < list2.size(); j++)
         {
             if(list.get(i).equals(list2.get(j))){
                 list2.remove(j);
             }
         }
     }
     
     //display the list2 Objects after removing existing objects
     for(String s : list2){
         System.out.println(s);
     }
}
}



JAVA - How To Use setActionCommand In Java Swing

JAVA - How To Use setActionCommand In Java Swing

Using setActionCommand In Java NetBeans

_______________________________________________________________________________

In this java Collection Tutorial we will see How To Use setActionCommand With Button
 In Java NetBeans .

Source Code:


package JavaDB_001;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;



public class Project extends JFrame {
    JButton btnOK,btnYES,btnNO;
    
public Project(){
    btnOK = new JButton("OK");
    btnYES = new JButton("YES");
    btnNO = new JButton("NO");
    
    btnOK.setActionCommand("OK");
    btnYES.setActionCommand("YES");
    btnNO.setActionCommand("NO");
    
    btnOK.addActionListener(new BtnAction());
    btnYES.addActionListener(new BtnAction());
    btnNO.addActionListener(new BtnAction());
    
    btnOK.setBounds(20, 20, 100, 20);
    btnYES.setBounds(140, 20, 100, 20);
    btnNO.setBounds(260, 20, 100, 20);
    
    add(btnOK);
    add(btnYES);
    add(btnNO);
    
    setLayout(null);
    setSize(400, 120);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().setBackground(Color.decode("#bdb76b"));
    setVisible(true);
}

public class BtnAction implements ActionListener{
    public void actionPerformed(ActionEvent e){
        String s = e.getActionCommand();
        if(s.equals("OK")){
          JOptionPane.showMessageDialog(null, "CLICK OK");
        }
        if(s.equals("YES")){
            JOptionPane.showMessageDialog(null, "CLICK YES");
        }
        if(s.equals("NO")){
            JOptionPane.showMessageDialog(null, "CLICK NO");
        }
    }
    }
public static void main(String[] args){
  new Project();
}
}



JAVA - How To Use JCheckBox In Java Swing

How To Use JCheckBox In Java NetBeans

_______________________________________________________________________________

package JavaDB_001;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;


public class Project extends JFrame {

    //declare JCheckBox Object
    JCheckBox ch;

public Project(){
     ch = new JCheckBox("CheckBox");
    //add Action to ch
    ch.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //if JCheckBox is selected
          if(ch.isSelected()){
              JOptionPane.showMessageDialog(null, "Checked");
          }
         // if JCheckBox is not selected
          else
              JOptionPane.showMessageDialog(null, "UnChecked");
        }
    });
    ch.setBounds(160, 30, 90, 20);
    add(ch);
    setLayout(null);
    setSize(400, 120);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().setBackground(Color.decode("#bdb76b"));
    setVisible(true);
}
public static void main(String[] args) throws IOException{
  new Project();
}
}

JCheckBox In Java
JCheckBox In JFrame




How To Make Money With Your Source Code

How To Make Money With Your Source Code

________________________________________________________________________________

▶ Build your website in minutes with Gator Builder


if you ask your self how i can sell my source code plugin, script you are in the right place
first let me introduce you this website: codecanyon .
CodeCanyon is part of Envato Market. At CodeCanyon, you can purchase and sell scripts and components for a variety of languages and frameworks, currently including JavaScript, PHP, ASP.NET.
also you can Browse the largest script and code marketplace on the web. Find WordPress plugins, jQuery plugins, Javascript, CSS and more. Save time, Buy code.
at this time is ranked in alexa:


Now Create An Envato Account Here
Create An Envato Account

fill your information
codecanyon account
you should confirm your registration

Now You Can Sell Your Android IOS Codes, Your WordPress Plugin, NavBar, and more



All you Have To do Now Is Start Making Awesome Source Code And Start Selling => CodeCanyon

You can also be an affiliate and sell codes from other person





Related Post:

How To Sell Your Source Code Online