C# - How To Create A Trapezoid Star Program In C#

C# - How To Create A Program To Print Trapezoid Star Program In C#

                                                                                                                                                     

In This C# Code We Will See How To Make A Program To Print A Trapezoid Using For Loop In C# Programming Language.

Source Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
 
           int k = 10;//number of spaces
           int d = 20;//number of stars

       
         //loop for 10 lines
        for(int i = 0; i < 10; i++){
            
             for(int l = k; l > 1; l--){
                Console.Write("  ");//two spaces
            }        
   
            //loop for d stars
            for(int j = 0; j < d; j++){
                Console.Write("*");
            }
 
            Console.WriteLine();
             
             k--;//discriminate the number of spaces
             d = d+4;//increment the number of stars

        }
        
            Console.ReadLine();
        }
    }
}
//////////OUTPUT:

Trapezoid Star In C#
Trapezoid In C#




C# - How To Create A Parallelogram Star Program In C#

C# - How To Create A Program To Print Parallelogram Star Program In C#

                                                                                                                                         

In This C# Tutorial We Will See How To Make A Program To Print A Parallelogram Using For Loop In C# Programming Language.

Source Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
 
                //loop for 40 stars
                for (int j = 0; j < 40; j++)
                {
                    Console.Write("*");
                }
 
                Console.WriteLine();
 
                //loop for spaces
                for (int l = 0; l <= i; l++)
                {
                    Console.Write("  ");//two space
                }
            }
            Console.ReadLine();
        }
    }
}

//////////OUTPUT:

Parallelogram Star In C#
 Parallelogram In C#




C# - How To Create A Equilateral Triangle Star Program In C#

C# - How To Create A Program To Print Equilateral Triangle Star Program In C#

                                                                                                                                         

In This C# Tutorial We Will See How To Make A Program To Print A Equilateral Triangle Using For Loop In C# Programming Language.

Source Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
              //20 = how much lines
       for(int i = 1; i <= 20; i++)
        {
            //loop to print stars

                for(int t = 1; t <= i; t++)
                {
                  Console.Write("*");  
                }
            //create a new Line
            Console.WriteLine();
        }
        
            Console.ReadLine();
        }
    }
}
//////////OUTPUT:
Equilateral Triangle Star In C#
Triangle In C#




C# - How To Get Primitive And Pairs Numbers From Int Array In C#

C# - How To Find Primitive And Pairs Numbers From Int Array In C#

__________________________________________________________________________

In This C# Code We Will See How To Find The Primitive Numbers Or The Pairs Numbers From An Int Array In C# Programming Language.

Source Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
 
        int[] ns = {2,54,3,24,5,23,76,13,10,19,88,41};
        
       //get pairs numbers
 
        Console.WriteLine("List Of Pairs Numbers");
        for (int i = 0; i < ns.Count(); i++)
        {
            if(ns[i]%2 == 0)
             Console.WriteLine(ns[i]);
        }
  
        Console.WriteLine("________");
  
        //get Primitive numbers
 
          Console.WriteLine("List Of Primitive Numbers");
          for(int i = 0; i < ns.Count(); i++){
            if(ns[i]%2 != 0)
            Console.WriteLine(ns[i]);
           }
        
            Console.ReadLine();
        }
    }
}
//////////OUTPUT:

Primitive And Pairs Numbers In C#
Primitive Pairs Numbers In C#




C# - How To Create A Star Pyramid In C#

C# - How To Create A Program To Print Pyramid Stars In C#

                                                                                                                                                     

In This C# Code We Will See How To Make A Program To Print A Pyramid Using For Loop
In C# Programming Language.

Source Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
             int v = 20;//the number of spaces
        
        //20 = how many lines
        for(int i = 1; i <= 20; i++)
        {
            //loop to print spaces
            for(int j = 1; j < v; j++)
            {
                Console.Write(" ");
            }
            
            v = v-1;
            //loop to print stars
                for(int t = 1; t < i*2; t++)
                {
                  Console.Write("*");  
                }
            //create a new Line
                Console.WriteLine();
        }
        
            Console.ReadLine();
        }
    }
}
OUTPUT:
Star Pyramid Program In C#
Pyramid In C#


JAVA - How To Update A JTable Row Using JOptionPane showInputDialog In Java NetBeans

java jtable update row

JAVA - How To Update A JTable Row Using JOptionPane.showInputDialog In Java NetBeans

__________________________________________________________________________

In This Java Code We Will See How To Update JTable Row Using JOptionPane showInputDialog In Java Programming Language.




Project Source Code:


package java_tutorials;

import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 * @author 1bestcsharp.blogspot.com
 */
public class Java_JTable_Update_Row_Using_JOptionPane extends javax.swing.JFrame {

    /** Creates new form Java_JTable_Update_Row_Using_JOptionPane */
    public Java_JTable_Update_Row_Using_JOptionPane() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        Btn_UpdateRow = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"1", "gfdferghty", "aghgh", "900"},
                {"2", "hiuytrefd", "hjyuèhdsc", "00"},
                {"3", "uitefgh", "uiytebgh", "-100"},
                {"4", "fhjuyhgfd", "bfdrtyui", "33"},
                {"5", "uytre", "iuytrfbhnj", "50"}
            },
            new String [] {
                "Id", "First Name", "Last Name", "Age"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        Btn_UpdateRow.setText("Update Row");
        Btn_UpdateRow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Btn_UpdateRowActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 447, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(172, 172, 172)
                        .addComponent(Btn_UpdateRow, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(37, Short.MAX_VALUE)
                .addComponent(Btn_UpdateRow, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26))
        );

        pack();
    }// </editor-fold>                        

// button update selected row
    private void Btn_UpdateRowActionPerformed(java.awt.event.ActionEvent evt) {                                              
        
        DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
        
// get selected row index
        int selectedRowIndex = jTable1.getSelectedRow();
        
// get selected row data 
        String id = model.getValueAt(selectedRowIndex, 0).toString();
        String fname = model.getValueAt(selectedRowIndex, 1).toString();
        String lname = model.getValueAt(selectedRowIndex, 2).toString();
        String age = model.getValueAt(selectedRowIndex, 3).toString();

 // get the entered data         
        String NewID = JOptionPane.showInputDialog(null,"Enter The New Id",id);
        String NewFN = JOptionPane.showInputDialog(null,"Enter The New First Name",fname);
        String NewLN = JOptionPane.showInputDialog(null,"Enter The New Last Name",lname);
        String NewAge = JOptionPane.showInputDialog(null,"Enter The New Age",age);
        
// set the new data into jtable row
        model.setValueAt(NewID, selectedRowIndex, 0);
        model.setValueAt(NewFN, selectedRowIndex, 1);
        model.setValueAt(NewLN, selectedRowIndex, 2);
        model.setValueAt(NewAge, selectedRowIndex,3);
    }                                             

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Update_Row_Using_JOptionPane.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Update_Row_Using_JOptionPane.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Update_Row_Using_JOptionPane.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Update_Row_Using_JOptionPane.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Java_JTable_Update_Row_Using_JOptionPane().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton Btn_UpdateRow;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration                   

}


////////OUTPUT:

jtable update row using joptionpane
jtable update row using joptionpane


Another Project Source Code:

package javaapp;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class Woirk extends JFrame {

    Object[] columns = {"ID","First Name","Last Name","Age"};
    Object[][] rows = {{1,"AA","BB",20},{2,"CC","DD",30},{3,"EE","FF",40},{4,"GG","HH",50}};
   
    public Woirk(){

        super("JFrame Name");
        
        JTable table = new JTable();
        
        JScrollPane pane = new JScrollPane();

        JButton button = new JButton("Upadate Row");
        
        JPanel panel = new JPanel(new BorderLayout());
        
        DefaultTableModel model = (DefaultTableModel)table.getModel();
        
        //set data to the model
        model.setDataVector(rows, columns);
        
        pane.setViewportView(table);

        panel.add(pane,BorderLayout.NORTH);
        
        panel.add(button,BorderLayout.SOUTH);
        
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
           
               String id;
               String fn;
               String ln;
               String age;
               
               //get values from yours showInputDialog
               id = JOptionPane.showInputDialog("Enter Your ID");
               fn = JOptionPane.showInputDialog("Enter Your First Name");
               ln = JOptionPane.showInputDialog("Enter Your Last Name");
               age = JOptionPane.showInputDialog("Enter Your Age");
               
               //get the selected row index
               int i = table.getSelectedRow();
               
               //set values to the specific place in jtable
               model.setValueAt(id, i, 0);
               model.setValueAt(fn, i, 1);
               model.setValueAt(ln, i, 2);
               model.setValueAt(age, i, 3);
            }
        });
        
        
        setContentPane(panel);
        setSize(800, 500);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setVisible(true); 
    }
    
    public static void main(String[] args){

         new Woirk();
    }
}

////////OUTPUT:
update a row from jtable
before click on the button

update jtable row using joptionpane.showinputdialog
after click on the button ; enter the data in the input dialog

jtable row updated with data from showinputdialog
jtable row updated with data from showinputdialog

See: Add A Row To JTable Using JOptionPane showInputDialog




JAVA - How To Add A Row To JTable Using JOptionPane showInputDialog In Java NetBeans

JOptionPane.showInputDialog

How To Insert A Row To JTable Using JOptionPane.showInputDialog In Java

__________________________________________________________________________

In This Java Code We Will See How To Add A Row To JTable From JOptionPane showInputDialog In Java Programming Language.




Project Source Code:


package java_tutorials;

import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 * @author 1bestcsharp.blogspot.com
 */
public class Java_JTable_Add_Row_Using_JOptionPane extends javax.swing.JFrame {

    /**
     * Creates new form Java_JTable_Add_Row_Using_JOptionPane
     */
    public Java_JTable_Add_Row_Using_JOptionPane() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        Btn_Add_Row = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Id", "First Name", "Last Name ", "Age"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        Btn_Add_Row.setText("Add Row");
        Btn_Add_Row.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Btn_Add_RowActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 410, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(134, 134, 134)
                        .addComponent(Btn_Add_Row, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(Btn_Add_Row)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

// button add row to jtable
    private void Btn_Add_RowActionPerformed(java.awt.event.ActionEvent evt)
 {                                            
        // get data from InputDialog
        String id = JOptionPane.showInputDialog("Enter The Id");
        String fname = JOptionPane.showInputDialog("Enter The First Name");
        String lname = JOptionPane.showInputDialog("Enter The Last Name");
        String age = JOptionPane.showInputDialog("Enter The Age");
        
        Object rowData[] = new Object[4];
        
        rowData[0] = id;
        rowData[1] = fname;
        rowData[2] = lname;
        rowData[3] = age;
        
        DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
        
        model.addRow(rowData);

    }                                           

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Add_Row_Using_JOptionPane.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Add_Row_Using_JOptionPane.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Add_Row_Using_JOptionPane.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Java_JTable_Add_Row_Using_JOptionPane.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Java_JTable_Add_Row_Using_JOptionPane().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton Btn_Add_Row;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration                   
}

=> OutPut :
add row to jtable
Add Row To JTable Using showInputDialog


Another Project Source Code:

package javaapp;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class Woirk extends JFrame {

    Object[] columns = {"ID","First Name","Last Name","Age"};

    public Woirk(){

        super("JFrame Name");

        JTable table = new JTable();

        JScrollPane pane = new JScrollPane();

        JButton button = new JButton("Add Row");

        JPanel panel = new JPanel(new BorderLayout());

        DefaultTableModel model = (DefaultTableModel)table.getModel();

        model.setColumnIdentifiers(columns);


        pane.setViewportView(table);

        panel.add(pane,BorderLayout.NORTH);

        panel.add(button,BorderLayout.SOUTH);
        
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

             String id;
             String fn;
             String ln;
             String age;

             //get th id from the first InputDialog
             id = JOptionPane.showInputDialog("Enter Your ID");

             //get th first name from the second showInputDialog
             fn = JOptionPane.showInputDialog("Enter Your First Name");

             //................
             ln = JOptionPane.showInputDialog("Enter Your Last Name");

             //................
             age = JOptionPane.showInputDialog("Enter Your Age");
             
             //add the row to the model
             model.addRow(new Object[]{id,fn,ln,age});
            }
        });
        
        setContentPane(panel);

        setSize(800, 500);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setLocationRelativeTo(null);

        setVisible(true);
        
    }
    
    public static void main(String[] args){

         new Woirk();
    }
    
}

////////OUTPUT:
insert row to jtable
before button click
enter values to the show input dialog
after button click: enter data to the showInputDialog
row inserted
Now Your Can See Your Row In The JTable 



See: Update A JTable Row Using JOptionPane showInputDialog