Showing posts with label Review Final Exam (Year 3). Show all posts

Review : Information System ( IS )



Thursday, December 20, 2012
Posted by Unknown

Java Programming Review Answer In Final Exam 22-23, 12, 2012




កូដនៅសរសេរនៅក្នុង EmployeeForm.java   គឺ​ ៖
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.List;
public class EmployeeForm extends Frame
                                                implements ActionListener {
                Vector <Employee> vs=new Vector<Employee>();
                TextField txtCode=new TextField();
                TextField txtName =new TextField();
                TextArea txtView=new TextArea();
                Choice cSex=new Choice();
                CheckboxGroup g=new CheckboxGroup();
                Checkbox cm=new Checkbox("Male",g,true);
                Checkbox cf=new Checkbox("Female",g,false);
                TextField txtSalary=new TextField();
                Button badd=new Button("ADD");
                Button bView=new Button("VIEW");
                Button bDelete=new Button("Delete");
                Button bClose=new Button("CLOSE");
                List lst=new List();

    public EmployeeForm() {
                this.setTitle("Employee Form ");
                this.setVisible(true);
                this.setSize(500,300);
                Panel p=new Panel();
                p.setLayout(new GridLayout(4,2,7,7));
                p.add(new Label("Code:"));p.add(txtCode);
                p.add(new Label("Name:"));p.add(txtName);
                p.add(new Label("Sex"));
                Panel p1=new Panel();
                p1.add(cm);p1.add(cf);
                p.add(p1);
                p.add(new Label("Salary"));p.add(txtSalary);
                this.add("North",p);
                p=new Panel();
                p.add(badd);
                p.add(bView);
                p.add(bDelete);
                p.add(bClose);
               
              this.add("Center",p);
             this.add("South",lst);


this.addWindowListener(new WindowAdapter(){

                                public void windowClosing(WindowEvent e){

                                                System.exit(0);}});
                badd.addActionListener(this);
                bView.addActionListener(this);
                bDelete.addActionListener(this);
                bClose.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e){
                if(e.getSource()==badd){
                                for (int i = 0; i<vs.size(); i++){
                                                if(vs.elementAt(i).code.equalsIgnoreCase(txtCode.getText())){
                                                                return ;
                                                }
                                }
                                Employee sobj=new Employee();
                                sobj.setCode(txtCode.getText());
                                sobj.setName(txtName.getText());
                                if(g.getSelectedCheckbox()==cm)
                                                sobj.setSex("Male");
                                else
                                                sobj.setSex("Female");
                                sobj.setSalary(Integer.valueOf(txtSalary.getText()));
                                vs.add(sobj);
                }else if (e.getSource()==bView){
                                g.setSelectedCheckbox(cm);
                                lst.clear();
                                for (int i = 0; i<vs.size(); i++)
                                                lst.add(vs.elementAt(i).toString());
                }else if (e.getSource()==bDelete){
                                                vs.removeElementAt(lst.getSelectedIndex());
                                                lst.remove(lst.getSelectedIndex());
                }else System.exit(0);
    }
    public static void main (String[] args) {
                new EmployeeForm();
  }
}
ការសរសេរកូដនៅក្នុង Employee.java គឺ
import java.util.*;
public class Employee implements Comparable {
                String code; String name; String sex; int salary;
    void setCode(String c){code=c; }
    void setName(String n){name=n; }
    void setSex(String s){sex=s; }
    void setSalary(int s){salary=s; }
    public String toString(){
                return code + " | " + name + " | " + sex + " | " + salary;
    }
    public int compareTo(Object obj){
                Employee sobj=(Employee)obj;
                return this.name.compareToIgnoreCase(sobj.name);
    }
}
 
Posted by Unknown

Review : Visual Basic.Net


ឧបមាថាគេមាន Form មួយដូចខាងក្រោម៖

 -          Button ADD ប្រើដើម្បីបញ្ចូល Pro_ID, Pro_Name, Price, Qty និងគណនា SubTotal ទៅក្នុង ListView ។​ បើ​មាន textbox ណាមួយគ្មានទិន្នន័យនោះគឺ​មិនអាច​ Add ទិន្នន័យចូល list បានឡើយ ។
   Private Sub btnAdd_Click() Handles btnAdd.Click
        If txtPro_ID.Text = "" Or txtName.Text = "" Or txtPrice.Text = "" Or txtQty.Text = "" Then
            Exit Sub
        End If
        Dim lItem As New ListViewItem
        lItem.Text = txtPro_ID.Text
        With lItem.SubItems
            .Add(txtName.Text)
            .Add(txtPrice.Text)
            .Add(txtQty.Text)
            .Add(txtPrice.Text * txtQty.Text)
        End With
        lstPro.Items.Add(lItem)
    End Sub 

-          Button Search ប្រើដើម្បីស្វែងរកទិន្នន័យ តាម Pro_ID នៅ​ក្នុង Listview ។ ករណីរកឃើញ​ត្រូវ Select Record នោះ​នៅ​ក្នុង​ Listview និង​បង្ហាញចំនួនដែល​រកឃើញនោះលើ Message Box ។ បើរកមិនឃើញគ្រាន់​តែបោះ​ជា Message ថារក​មិន​ឃើញ​ប៉ុណ្ណោះ ។
    Private Sub btnSearch_Click() Handles btnSearch.Click
        For i = 0 To lstPro.Items.Count - 1
            If lstPro.Items(i).Text = txtPro_ID.Text Then
                lstPro.Items(i).Selected = True
            Else
                lstPro.Items(i).Selected = False
            End If
        Next
        lstPro.Select()
        If lstPro.SelectedIndices.Count > 0 Then
            MsgBox("Total Found : " & lstPro.SelectedIndices.Count)
        Else
            MsgBox("Not Found")
        End If
    End Sub 

-          Button Remove ប្រើសម្រាប់លុប seleted record ពីក្នុង Listview ចោល
Private Sub btnRemove_Click() Handles btnRemove.Click
        For i = 0 To lstPro.SelectedIndices.Count - 1
            lstPro.Items.RemoveAt(lstPro.SelectedIndices(0))
        Next
End Sub 

-          ចូរបង្កើត Properties និង Method នៅក្នុង Class Module ដើម្បីអាចយកទៅ​ប្រើ​សម្រាប់​ប្រព័ន្ធខាងលើ៖
Public Class Product
    Private _Pro_ID As String
    Private _Pro_Name As String
    Private _Price As Double
    Private _Qty As Double
    Property Pro_ID
        Set(ByVal value)
            _Pro_ID = value
        End Set
        Get
            Return _Pro_ID
        End Get
    End Property
    Property Pro_Name
        Set(ByVal value)
            _Pro_Name = value
        End Set
        Get
            Return _Pro_Name
        End Get
    End Property
    Property Price
        Set(ByVal value)
            _Price = value
        End Set
        Get
            Return _Price
        End Get
    End Property
    Property Qty
        Set(ByVal value)
            _Qty = value
        End Set
        Get
            Return _Qty
        End Get
    End Property 
End Class

Public Class ProductStore
    Private store As Collection
    Public Sub addProduct(ByVal obj As Product)
        store.Add(obj)
    End Sub
    Public Function getProduct(ByVal index As Integer) As Product
        Return store.Item(index)
    End Function
End Class


យើងអាចប្រកាស Local Variable ដោយប្រើ Keyword Dim និង Static
Mid មានប៉ារ៉ាមែត្រចំនួន៣ : Mid(String,Start,Len)
Keypress Event កើតឡើងនៅពេលដែលយើង Press any key
Default Event របស់ Label គឺ Event_Click
ដើម្បីចាកចេញពី Procedure យើងប្រើ Keyword Exit Sub
ដើម្បីលុបធាតុចេញពី Listbox គេប្រើ method : ListBox.Items.RemoveAt(index)
Redim, Redim Preserve ជា Keyword ប្រើសម្រាប់ប្រកាស Array Dynamic
Accept Button ជា Property របស់ Form
Ubound() ជា Built-in function សម្រាប់ប្រាប់ចំនួនធាតុធំបំផុតរបស់ Array
ដើម្បីកំណត់ប្រវែងនៃ Text ដែលបង្ហាញនៅក្នុង Textbox គេចប្រើ Property : MaxLength
Files ដែលអាច Load ដើម្បីបង្ហាញរូបភាពនៅលើ Picture Box បាន មាន Extension .bmp, .jpg, .gif
Dim MyArray(2,3) As Integer នាំឲ្យ Array នេះ មាន 6 Elements
Default Event របស់ Listbox គឺ Event_SelectedIndexChanged

TextBox Control

     TextBox Control is used to add text or to display text in a form. This is one of the most used controls, as text is vital for GUI based applications.

Posted by Unknown

Like ដើម្បីទទួលបានអ្វីថ្មី

Powered by Blogger.

I love Cambodia

ថ្នាក់មហាវិទ្យាល័យឆ្នាំទី៤ សាកលវិទ្យាល័យភូមិន្ទភ្នំពេញ

ភាពយន្ត ចម្រៀង កំប្លែង ផ្សេងៗ

ចំនួនអ្នកចូលទស្សនា

Statistics

ស.វិទ្យាល័យភូមិន្ទភ្នំពេញ

- Copyright © 2013 សុធាសម្រាប់ចែករំលែក - Powered by Blogger - រចនាដោយ Phorn Sothea (student at RUPP(year 4) -