Friday 31 August 2012

VB - Check Box, Option Button and Frame


Step1: Place One Label, one Text Box, Two Frames, Two Option Buttons, Three Check Boxes and a Command Button on the Form1
Step2: Rename the Control Caption in the Property Window as follows
Form1 -> Option & Check
Label1 -> Enter Text Here:
Frame1 -> Case
Frame2 -> Effects
Option1 -> Upper
Option2 -> Lower
Check1 -> Strike Through
Check2 -> Under Line
Check3 -> Bold
Command1 -> Exit
Change the Text1 Properties as multiline True and ScrollBars as Both
Enter the following codes in the corresponding controls
Private Sub Check1_Click()
If Check1.Value = 1 Then
Text1.Font.Strikethrough = True
Else
Text1.Font.Strikethrough = False
End If
End Sub

Private Sub Check2_Click()
If Check2.Value = 1 Then
Text1.Font.Underline = True
Else
Text1.Font.Underline = False
End If
End Sub

Private Sub Check3_Click()
If Check3.Value = 1 Then
Text1.Font.Bold = True
Else
Text1.Font.Bold = False
End If
End Sub

Private Sub Command1_Click()
End
End Sub

Private Sub Form_Load()
Option2.Value = True
End Sub

Private Sub Option1_Click()
If Option1.Value = True Then
 Text1.Text = UCase(Text1)
 End If
 End Sub

Private Sub Option2_Click()
If Option2.Value = True Then
Text1.Text = LCase(Text1)
End If
End Sub

 Step3: Run the Application by pressing F5

VB Login Form


Step 1: Place two Labels, two Text boxes and two Command Buttons on the Form1 window
Step2: Reaname Label1 as username and Label2 as password (properties window change caption name).
Step3:Delete TextBox Text Property so that TextBox becomes empty.
Step4: Change CommandButton1 caption property as Login and CommandButton2 caption property as Cancel.
Step5: Click on Project from menu bar and select Add Form, click open then Form2 will be opend.
Step6: Take a Label on Form2 and change its text Property as WELCOME to ORACLE SQL.
Step7: Double click on commandbutton1 on Form1 and enter the following code
Private Sub Command1_Click()
If Text1.Text = "scott" And Text2.Text = "tiger" Then
Form2.Show
Form1.Hide
Else
MsgBox "Invalid Username and Password"
Text1.Text = ""
Text2.Text = ""
End If
End Sub

Step8: Select TextBox2 Password Character Property as *

Step9: Double click on Command Button2 and enter the following code

Private Sub Command2_Click()
End
End Sub

Step10: Press F5 and run the program

sliders



     import java.awt.*;
     import javax.swing.*;
     import java.awt.event.*;
     import javax.swing.event.*;

      public class sliders extends JFrame implements ChangeListener
     {
             Container c;
             JLabel l1,l2,l3;
             JSlider s1,s2,s3;
             JTextField t1;
           public sliders()
           {
                l1=new JLabel("Red");
                l2=new JLabel("Green");
                l3=new JLabel("Blue");

                s1=new JSlider();
                s2=new JSlider();
                s3=new JSlider();

               setSize(250,300);
               setDefaultCloseOperation(0);
               c=getContentPane();
               c.setLayout(new FlowLayout());
      
               s1.setMinimum(0);
               s2.setMinimum(0);
               s3.setMinimum(0);

              s1.setMaximum(255);
              s2.setMaximum(255);
              s3.setMaximum(255);
              
                 s1.setMajorTickSpacing(50);
              s2.setMajorTickSpacing(50);
      
             s3.setMajorTickSpacing(50);
            
            s1.setPaintTicks(true);
            s2.setPaintTicks(true);
            s3.setPaintTicks(true);

             s1.setPaintLabels(true);
             s2.setPaintLabels(true);
             s3.setPaintLabels(true);

               c.add(l1);   c.add(s1);
               c.add(l2);   c.add(s2);
               c.add(l3);   c.add(s3);

              s1.addChangeListener(this);
              s2.addChangeListener(this);
              s3.addChangeListener(this);
          }

        public void stateChanged(ChangeEvent e)
       {
            int r,g,b;
           Color c1;
            r=s1.getValue();
           g=s2.getValue();
           b=s3.getValue();

             c1=new Color(r,g,b);
             c.setBackground(c1);
        }

      public static void main(String args[])
      {
          color m=new color();
          m.setVisible(true);
      }
  }

menu


   import java.io.*;
   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;

    public class Menu extends JFrame implements ActionListener
   {
         Container c;
         JTextArea ta;
         JMenuBar mbar1;
         JMenu file,edit;
         JMenuItem fnew,fopen,fsave,fexit,ecut,ecopy,epaste,eclear;
         JLabel l1;
         JToolBar sbar,tbar;
         JButton b1,b2;
         JProgressBar pbar;
       
         public Menu()
        {
             super("WINDOW");
             setSize(500,400);
             setDefaultCloseOperation(0);
             setLocation(50,50);
             c=getContentPane();
            ta=new JTextArea(10,40);
            pbar=new JProgressBar();
            Font f1=new Font("Times New Roman",1,25);
            pbar.setFont(f1);
            pbar.setMinimum(1);
            pbar.setMaximum(200);
            pbar.setStringPainted(true);
            pbar.setValue(50);
            c.add(pbar);
            ta.setFont(f1);
           ta.setLineWrap(true);
           ta.setWrapStyleWord(true);
           c.add(new JScrollPane(ta));
           mbar1=new JMenuBar();
           file=new JMenu("File");
           file.setMnemonic('f');
           fnew=new JMenuItem("New");
           fopen=new JMenuItem("Open");
           ImageIcon ic1=new ImageIcon("sunlogo62x30.gif");
           fsave=new JMenuItem("Save",ic1);
            fexit=new JMenuItem("Exit");
           fexit.setMnemonic('X');
           file.add(fnew);          file.add(fopen);
           file.add(fsave);     file.addSeparator();
          file.add(fexit);      mbar1.add(file);
          edit=new JMenu("Edit");
          ecut=new JMenuItem("Cut");
          ecopy=new JMenuItem("Copy");
          epaste=new JMenuItem("Paste");
          eclear=new JMenuItem("Clear");
          edit.add(ecut);    edit.add(ecopy);
         edit.add(epaste);  edit.add(eclear);
         mbar1.add(edit);
         setJMenuBar(mbar1);
         tbar=new JToolBar();
         sbar=new JToolBar();
         sbar.setFloatable(false);
         l1=new JLabel("READY");
         b1=new JButton(new ImageIcon("sunlogo62x30.gif"));
         b2=new JButton(new ImageIcon("save.gif"));
          tbar.add(b1);         tbar.add(b2);
         sbar.add(l1);
         c.add(tbar,BorderLayout.NORTH);
         c.add(sbar,BorderLayout.SOUTH);
          fexit.addActionListener(this);
          fopen.addActionListener(this);
          fsave.addActionListener(this);
        b1.addActionListener(this);
        b2.addActionListener(this);
      }
           

           
            public void actionPerformed(ActionEvent ae)
     {
       if(ae.getSource()==fnew)
      { 
          ta.setText(" ");   
      }
    
             if(ae.getSource()==fopen||ae.getSource()==b1)
                  {
           JFileChooser jfc=new JFileChooser();
           File d=new File("D:/jdk1.4/bin");
           jfc.setCurrentDirectory(d);
           jfc.showOpenDialog(this);
          File f=jfc.getSelectedFile();
          setTitle(f.toString());
          try
          {
             FileReader fr=new FileReader(f);
             ta.read(fr,ta);
          }
         catch(Exception e){   }
     }

     if(ae.getSource()==fsave||ae.getSource()==b2)
     {
         JFileChooser jfc1=new JFileChooser();
          File d=new File("D:/jdk1.4/bin");
          jfc1.setCurrentDirectory(d);
          jfc1.showSaveDialog(this);
         File f=jfc1.getSelectedFile();
         setTitle(f.toString());
         try
         {
             FileWriter fw=new FileWriter(f);
             ta.write(fw);
        }
        catch(Exception e){   }
    }
                  if(ae.getSource()==fexit)
    {
        int x=JOptionPane.showConfirmDialog(this,"DO U WANT TO QUIT?", "Exit Dialog" ,0);
        if(x==0) 
          System.exit(0);
      }
   }
     public static void main(String a[])
     {
      Menu m=new Menu();
      m.setVisible(true);
     }

 } 
output: