Credits

Tuesday, March 30, 2010

Rainy Days on Students

Summer  vacation has officially started for us in STI Gensan and while I encoded my grades for the subjects I was assigned with, the computer laboratory was all in chaos as lab personnel worked on reprogramming and repairing the computer units in time for summer and first semester classes.


Other schools on the other hand make use of summer off to do school office construction, renovation, repairs which including putting up new classrooms with sturdy fixtures like the tables, chairs, faucet  and good lightings among other things. 


As we hurdle the extreme weather due to El Nino, schools nationwide also anticipate the possible wrecks of rainy season come May.  I can only pity some remote or overcrowded schools where classrooms are only held under hovering trees or where students have to travel on foot for hours just to get to their  schools in spite of the weather. 


Education in the Philippines is one of the weakest and the rippling effect is only depressing. I wish with the upcoming elections, education system can be better improved and be really considered as one of the top priorities to be addressed. 

Jobs Less for Graduates?

With countless of graduations being held nationwide here in the Philippines, the new graduates are expected to be excited, hopeful,  courageous but reluctant as well. We can't practically blame them when in fact, there are a number of old graduates who are either unemployed or jobless themselves.


The Philippine government claims that there is a decline from unemployment statistics which is supported by the Philippine Census as shown below:

EMPLOYMENT RATE REPORTED AT 92.7 PERCENT
IN JANUARY 2010
Results from the January 2010 Labor Force Survey (LFS)


 Philippines      January 2010 1/ January 2009  
  Population 15 years and over (in '000)  60,208   /  58,657
  Labor Force Participation Rate (%)    64.5  /  63.3
  Employment Rate (%)            92.7  /  92.3
  Unemployment Rate (%)       7.3  /     7.7
  Underemployment Rate (%)       19.7   /  18.2

Notes: 1/ Estimates for January 2010 are preliminary and may change.
2/ Population 15 years and over is from the 2000 Census-based population projections.


But, mostly the works are transient or temporary and mainly on low - skill industries.  With El Nino hype, more agriculture employees are bound to be jobless and would rather seek other works. So, the statistics above is expected to change. 


No wonder that most graduates would opt to work abroad not only because the pay in the Philippines is meager but also the job opportunities are simply limited. 


I can only wish  that the graduates  these days are equipped with the right skills so that they can get a better employment here or abroad.

 

Creating Login Form in Java

Our classes in Java Programming are done and so I can take a break from creating sample exercises. But, I  wish not to stop giving notes on Java programming here. So, I dug into my Java project and found this login program.


I made this program in NetBeans 6.0 with MySQL.   

[+/-] show/hide



/*
* LogInFrm.java
*
* Created on November 29, 2008, 11:07 AM
*/

import java.sql.*;
import javax.swing.JOptionPane;

/**
*
* @author rosilie lim
*/
public class LogInFrm extends javax.swing.JFrame {
Connection connection;
Statement statement;
SetConnection sconn;

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

/** This method is called from within the constructor to
* initialize the froorm.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
txtUserName = new javax.swing.JTextField();
cbUserType = new javax.swing.JComboBox();
txtPassword = new javax.swing.JPasswordField();
jPanel3 = new javax.swing.JPanel();
bOk = new javax.swing.JButton();
bClose = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(204, 0, 0));

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
jLabel1.setText("Log-In");
jPanel1.add(jLabel1);

jPanel2.setBackground(new java.awt.Color(255, 153, 153));

jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel2.setText("User Name:");

jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel3.setText("User Type:");

jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel4.setText("Password:");

cbUserType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrator", "User" }));

txtPassword.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtPasswordActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(94, 94, 94)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtPassword)
.addComponent(cbUserType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE))
.addContainerGap(92, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(cbUserType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(74, Short.MAX_VALUE))
);

jPanel3.setBackground(new java.awt.Color(153, 0, 0));

bOk.setText("Ok");
bOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bOkActionPerformed(evt);
}
});
jPanel3.add(bOk);

bClose.setText("Cancel");
bClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bCloseActionPerformed(evt);
}
});
jPanel3.add(bClose);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 275, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
);

pack();
}//


private void bCloseActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
}

private void bOkActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ResultSet rs = null;
sconn = new SetConnection();
String passwd = new String(txtPassword.getPassword());

boolean con = sconn.setConn(txtUserName.getText(),passwd,getContentPane());
if(con == true){
connection = sconn.getConn();
statement = sconn.getStatement();

String qry = "SELECT * FROM employees WHERE username = '" +
txtUserName.getText()+"' AND password = '" +
passwd+"'";

try{
rs = statement.executeQuery(qry);

boolean found = rs.next();

if(found){
MainProgram mp = new MainProgram();
mp.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
mp.setVisible(true);
}
else{
JOptionPane.showMessageDialog(getContentPane(),
"Invalid User","Error",JOptionPane.ERROR_MESSAGE);
}

}catch(SQLException sqle){}
}
}

private void txtPasswordActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
bOk.doClick();
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LogInFrm().setVisible(true);

}
});
}

// Variables declaration - do not modify
private javax.swing.JButton bClose;
private javax.swing.JButton bOk;
private javax.swing.JComboBox cbUserType;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPasswordField txtPassword;
private javax.swing.JTextField txtUserName;
// End of variables declaration

}

Parttime or Fulltime Teaching?

For those who seek to get rich through this career, then you are on the wrong track. LOL! For one, this job is one of the underpaid professions in the Philippines.   The basic rate of a masters - degree - holder professor will only range  between Php 10000.00 - 15000.00 for a 24 - unit load or 24 contact hours a week (at least).


With this meager pay, we are plagued by paper works, observations, and delinquent students. I tried giving up this job for a more interesting one, but I simply realized I am deep in love with teaching in spite of the drawbacks.


However,  so I won't get bored again, I decided to pursue the family business while I go parttime on schooling.  The decision was  only timely since we will soon be opening our boutique at the mall and shall be needing lots of boutique stuffs including POS systems  to help with the sales. 


Pursuing a career is always a personal decision. But, regardless of what we choose, it is always important that we are happy with our job otherwise everyday can be a frustrating day to start and end with. 


I still envision myself teaching in spite of age, salary and school.  Should I go parttime or fulltime? It does not really matter provided I can do both teaching and doing business.

Worthwhile Summer Fun

A number of schools are finally done with their regular classes. My old graduate school alma mater, MSU, shall hold their graduation this April 9.  My employer school, STI Gensan,  shall have the graduation ceremony on the 6th while the undergraduates have long enjoyed their summer vacation when the last day of exam concluded last March 27. 


So, whenever I wander around malls, I get to see my old students and some struck me since they were busy filling up resumes for summer jobs. I somehow remembered how I earned a living while I was still in school while others are off to somewhere else.


But, for those who choose not to work this summer, fun time can always be achieved if they choose to maximize their vacation on sports  or vacation  with loved ones.  Others use the time for trainings or seminars to enhance their skills. Whatever we choose to use our free time on, we can always consider first if it can be a worthwhile fun.

Done With Schooling

I turned in my clearance to the school administrators after I have completed all the paper works and requirements for second semester. So, officially tomorrow, I will be on vacation already. YEPEY!!!!

But, indeed, teaching works are always tougher especially on checking papers and making the grades. It is always difficult to fail students but I don't feel remorse for giving failed grades for those who did not care at all to earn a passing mark for their own sake.


There are practically a number of reasons why students choose to drop from school. For one, it is always finances, then followed by lack of interest among other things.


But, I remain hopeful that those who dropped from school can go back at time when they can be ready.

Friday, March 26, 2010

Summer Vacation for Students and Teachers

We are now on final examination and everyone is simply looking forward to that two - month vacation. Although the vacation for some shall bear no pay, for others it still be a continuing work  with long breaks in between.


I shall personally attend to the business again and we hope to have the mall space construction soon and shall be off to see my younger sibling in Manila.  Since for most of us, we won't be receiving any compensation, we still wish living will be less  difficult these coming months.  


It will somehow help if life protections are there especially in difficult times like accidents or illness.  I heard there is instant life insurance quote  that can be checked for that much needed security blankets. 


Although life is harder because of the impact of recession, but we can only be practical and consider what can practically happen to us in the future. Thus, even if a teacher's salary is that meager, I still prioritize saving for my insurances.  I don't want to burden my loved ones just in case, I get sick or get older and cannot work anymore. I can only anticipate the future and be ready.

Other Java Polygon Sample

We can practically draw any shape. I have the sample program below that shows a big octagon as a road sign. Also, we can copy sections of our graphics area by using copyArea method.


See the program below that displays copying of the rectangle to another area. I wish to draw the  text size to be bigger to go with the octagon's size. But we can always resize all these to bigger or smaller ones.

[+/-] show/hide



import java.applet.*;
import java.awt.*;


public class GraphicsPolygons extends Applet {
int xPoints[]={200,100,100,200,300,400,400,300};
int yPoints[]={100,200,300,400,400,300,200,100};
int size=xPoints.length;
Color newColor=new Color(.80F,1F,.50F);

public void init()
{
setBackground(Color.red);

}

public void paint(Graphics g)
{


g.setColor(newColor);
g.fillPolygon(xPoints,yPoints,xPoints.length); //to fill a solid polygon
g.drawRect(200,400,100,50);
g.setColor(Color.black);
g.drawString("STOP", 250, 250);
g.copyArea(200,400,101,51,400,0);
}}

Another Java Graphics Sample

I have this sample exercise for my students to illustrate the use of buttons with Graphics methods and use of Font class to the works. 


See  the sample program.

[+/-] show/hide



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//
public class GraphicsQuiz extends JApplet implements ActionListener{
Container con = getContentPane();
JButton increase = new JButton ("increase");
JButton decrease = new JButton ("decrease");
JLabel lbl=new JLabel(" S T I");
int size=10;

public void init()
{
con.setLayout(new FlowLayout ());


con.add(increase);
con.add(decrease);
con.add(lbl);
increase.addActionListener(this);
decrease.addActionListener(this);
setBackground(Color.red);
}


public void actionPerformed(ActionEvent e)
{ Object source =e.getSource();

if (source==increase)
{Font myFont=new Font("Arial",Font.BOLD, size+=10);
lbl.setFont(myFont);
if (size>50)
size=10;
repaint();}
else
if (source==decrease)
{Font myFont=new Font("Arial",Font.BOLD, size-=10);
lbl.setFont(myFont);
if (size<0)
size=10;

repaint();}

}
}

Wednesday, March 17, 2010

The Absentee Teacher

I chose to be absent today from my laboratory class to attend to my business requirements. So, the students were only happier to know that I won’t be with them. Geez! They just want to play around as much as they can. LOL!


I have to make use of the free time to get ready for next day’s class. This is one of the downsides of teaching, before the day is over, the teacher must be ready for the next day’s teaching sessions.


Even if I have to stay in the store and deal with work while enjoying my fave movie, I have to maximize my time and work on what is important.


My teaching days will soon be over so, I just have to endure a little, then, it will be a long rest for me. Final quarter is always busier for students and teachers, so the papers works shall be tougher in the coming days.


With stress, aging, weight gains, wrinkles and all are said to be consequences of hgh  decrease. Thus, HGH supplements may help bring back the glow of youth.


I may able to hide my age through my wardrobes and skin care, but the symptoms of aging begin to appear and these indeed hit a delicate nerve.  


I hope the stress from my teaching will soon be over.  

Happier Graduating Students

Since the class is almost over this March, graduating students from all levels are done with their final exams and now busy with their graduation practices.


Now that the burden of school is finally done, they can all move on to the next level and start looking for a job and facing the real world. 


DepED, CHED and TESDA mandated schools of all levels to cut down their graduation costs and to simply go for simple programs. 


I don't have any graduating student but my youngest sibling is graduating from high school. She is pretty excited to being in college and have that privileges. LOL!


Commendations are truly due for these graduating students and for the parents who supported them. 

Creating Polygons

Other than the ones discussed, polygons  can be created through Java Graphics class.  A polygon can be made in two ways: polygon methods and Polygon class.


The polygon must take three arguments, find below the method syntax:


fillPolygon(xPoints_array,yPoints_array,array_length) - to draw a solid and filled shape through set of x and y points with number of points indicated. 


To make use of Polygon class with similar effect, we can use the constructor below:

Polygon newPolygon = new Polygon(xPoints,yPoints,size);

drawPolygon(newPolygon);

[+/-] show/hide




import java.applet.*;
import java.awt.*;

public class GraphicsRectsCircles extends Applet {
int xPoints[]={42,52,72,52,60,40,15,28,9,32,42};
int yPoints[]={38,62,68,80,105,85,102,75,58,60,38};
int size=xPoints.length;

public void paint(Graphics g)
{

g.setColor(Color.yellow);
//g.drawPolygon(xPoints,yPoints,xPoints.length); //to draw a polygon outline
g.fillPolygon(xPoints,yPoints,xPoints.length); //to fill a solid polygon
// or through the lines below, produces same result
Polygon myPolygon=new Polygon(xPoints,yPoints,size);
g.fillPolygon(myPolygon);
}
}

School Vacation Very Soon

Summer is vacation time for most students and teachers in the Philippines. And since there are no works to be busy with, weights are bound to get wild and nasty. But, weather in the Philippines is always warmer during summer days, thus, it will be wiser to spend the days outdoor. Most of the Filipinos will surely swarm beaches, pools and malls once the peak hot season will strike in.


But, since aging decreases our metabolism, we get to store fats longer than the younger ones. Obesity has been a global issue, this very thing makes drug experts create various weight pills. But, one can only be careful since there are stories like relacore reviews of drugs with less efficiency and worst, with side effects.


Drugs and plastic surgery are attractive options to reducing weights but, as a responsible individual, we have to consider the pro’s and con’s of any option we wish to pursue. It will help more, if we are well informed and educated.


So, come summer, we will sure have fun losing weight and enjoying the sun.

Drawing Java Arcs

We can also create arcs from circles made. 


Use the commands below for  the arcs.


drawArc(x, y, width,height,beginning_arc_position, arc_angle_to_draw); - draws an outline of an arc;

fillArc(x, y, width,height,beginning_arc_position, arc_angle_to_draw); - draws a solid fill of an arc;


The arc starts at 0 degree at 3:00 position and moves counterclockwise. If the arc position is set to negative, then it starts from the bottom half of the circle and follows the usual direction. The arc angle shall be the angle from given point to ending point.


See the program below for given sample. 


[+/-] show/hide



import java.applet.*;
import java.awt.*;

public class GraphicsRectsCircles extends Applet { 
public void paint(Graphics g)
{
setBackground(Color.red);
g.setColor(Color.green);
g.fillArc(120, 160, 100, 100, 20, 320);
g.fillArc(200, 160, 100, 100, 340, 40);

    
}
}

Creating Java's Shapes and Lines

Apart from setting background colors and font styles, lines and polygons can be created through Graphics class.


The following are the methods that can be used to draw lines, rectangles, ovals, circles and polygons.  The x,y are the coordinates for a given starting or ending point.


drawLine(x1,y1,x2,y2) - to draw a line from beginning point to ending point;


drawRect(x,y,width,height)- to draw an outline of a rectangle at given starting point with width and height in pixels;


fillRect(x,y,width,height)- to draw a filled and solid rectangle at given starting point with width and height in pixels;


clearRect(x,y,width,height)- to draw an "empty" rectangle at given starting point with width and height in pixels but follows  the background color unlike other commands that follow the set colors;


drawOval(x,y,width,height)- to draw an outline of a oval at given starting point with width and height in pixels;


fillOval(x,y,width,height)- to draw a filled and solid oval at given starting point with width and height in pixels;


If the width and height are the same for rectangles, then a square is formed. On the other hand, a circle is formed if same dimensions are set for ovals.


drawRoundRect(x,y,width,height,arc_width,arc_height) - to draw a round corner edge for a rectangle or square.


See the program below for given illustration.



[+/-] show/hide




import java.applet.*;
import java.awt.*;

public class GraphicsRectsCircles extends Applet {

public void paint(Graphics g)
{
//these set of lines draws a square
g.setColor(Color.blue);
g.drawLine(5,5,50,5);
g.drawLine(5,50,50,50);
g.drawLine(5,5,5,50);
g.drawLine(50,5,50,50);

g.setColor(Color.black);
g.drawRoundRect(20,20,80,80,0,0);  //draws a square 
g.drawRoundRect(120,20,80,80,10,10); //draws a square with small round corner 
g.drawRoundRect(220,20,80,80,40,40);  //draws a square with big round corner
g.drawRoundRect(320,20,80,80,80,80);  //draws a circle 

g.setColor(Color.blue);
setBackground(Color.pink);
g.fillRect(20, 160, 80, 80);   //draws a solid rectangle 
g.clearRect(40, 180, 50, 50); //draws a clear  or empty rectangle 


}

Tuesday, March 16, 2010

School on Last Lap

In the coming week, our school shall officially hold our final examination and this means that after the last day of the test, everyone is finally done with going to and fro school for teaching and schooling.


As for us teachers, we are bound to submit our paper requirements before we say that the job for second semester is finally over.


As soon as the exam is over, I wish to go back to my morning rudiments which include jogging and biking. With nothing much to do this summer vacation, I wish to maximize the opportunity to do exercise, create my e-commerce site and enjoy family time. 


There are indeed various means to lose that unwanted weight. We can always weigh these  quick weight loss tips  and try them according to our lifestyles and resources. Regardless of our chosen  weight - loss alternative, we always have to consider our health status before anything else. We don't want to compromise our health over other things, right?  Studies show that weight loss is more difficult for aged people, thus, it may help to consider other safe options which include surgery and diet pills. 


I wish to bring my kid's weight down too this summer. So, most likely, I may enroll him to  swimming and karate sessions.


We are all pretty excited that we will be soon off to vacation and fun recreations. 

Creating Java Graphics Instance

We can create an instance of Graphics class outside our paint method. We can do this by using the line below:

Graphics yourObject = getGraphics();


With this command, we can now use Graphic methods the same way we use them inside paint.


See sample program to illustrate this. 



[+/-] show/hide



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

public class GraphicsDemoCreateObject extends Applet implements ActionListener{
String companyName = new String (" S T I");
JButton moveButton = new JButton ("Move it.");
Color newColor = new Color(100,20,255);//creating your own color
Font hell2Font = new Font ("Helvetica", Font.ITALIC, 12);
int x = 10, y = 50;

public void init()
{
setBackground(Color.yellow);
add(moveButton);

moveButton.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
Graphics gr = getGraphics();
gr.setFont(hell2Font);
gr.setColor(newColor);
gr.drawString(companyName,x+=20,y+=20);
//the condition below is to control the movement within applet page size
if (y>getSize().height)
moveButton.setEnabled(false);
}
}

Java's Use of Colors

Part of Java's use of Graphics class is the use on colors. To set color to our text, we can use the code below:

graphicObject.setColor(color_constant);  

ex:

myObject.setColor(Color.pink);


To use our own color variants, we can have a constructor for color:

Color colorObject = new Color(red_extent,green_extent,blue_extent);

ex:

Color newColor = new Color(200,10,255); 

 where this constructor can create a light blue color. Then we use the same to set the text color as indicated below:

myObject.setColor(newColor);


A program below demonstrates various color variants.



[+/-] show/hide



/* sample program on graphics */

import java.applet.*;
import java.awt.*;


public class GraphicsDemoColor extends Applet {

Font littleFont = new Font("Helvetica",Font.ITALIC,6);


public void paint(Graphics gr){
int r,g,b;
int x=0,y=0;

for(r=255;r>=0;r-=20)
for(g=255;g>=0;g-=20)
for(b=255;b>=0;b-=20)
{
Color variety = new Color(r,g,b);
gr.setColor(variety);
gr.drawString("X", x, y);
x+=5;
if (x >=400)
{ x=0;
y+=10;

}
}


}
}



Teaching - Blogging For Me

As an IT teacher, it helps when I can find online resources and alternatives to help my students learn more.


Since I teach Java programming among freshmen students, I normally bring my notebook to class and hook it up with the school's projector. This makes the teaching easier and less distressful. But, writing programs takes time too that whenever I have sample source codes for classroom references and assessments, I normally upload the files to our Yahoo group for public viewing and download.  That way, students in - and - out from  school can check the resources to make their learning more effective and efficient.  Also, it helps when I post my lectures and sample programs on this techie blog. 


But, if I really want to make this techie blog draw more traffic so I can reach out even to other Java students not in my class, I may as well use seo tools  for efficient and effective results.   


I never really understood the concepts of SEO and they can indeed drive anyone nuts but with the right info and effective and simple guides on this powerful search strategy, my education site can be more known. 


At least, it helps that there are free resources online that I can check to get this techie blog kicking. And, my students and I can only be  happier!

Another Java Graphics Program

As indicated in the previous post, we can write our own paint() inside an Applet's program. When we do this we create an object of Graphics class which we can use for our graphics operations. 


The paint() is actually called whenever we run our applet, resize, minimize and restore the applet page.  So, basically, this method works in close hand with other applet's methods.   However, paint() is not invoked directly. It is actually called whenever we use repaint() which calls for update() and in turn, calls for paint(). 


To see the application of this idea, check the sample program below.

[+/-] show/hide



/* sample program on graphics */

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class GraphicsDemoPaint extends Applet implements ActionListener{
Button pressButton = new Button ("Press");
public void init(){
add(pressButton);
pressButton.addActionListener(this);
}

public void paint(Graphics g){
System.out.println("in paint method");
}

public void actionPerformed(ActionEvent e)
{
repaint();
}
}

Java's Graphics

Java is capable of employing graphics operations including creating of geometric shapes and making graphic designs.


This is supported by AWT package and since it is an abstract class, it can be instantiated directly. Typical graphics' methods include drawString() which places some text on x,y coordinates, setColor() for text colors and setFont() for changing font types, styles and sizes.  These methods can be done inside paint() method as one of Applet's inherent methods.


See the program below for sample illustration. 

[+/-] show/hide



/* sample program on graphics */

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class GraphicsDemo2 extends Applet {
String companyName = new String("STI");
Color newColor = new Color(100,20,255);//creating your own color
Font bigFont = new Font("Helvetica",Font.ITALIC,24);


public void paint(Graphics gr){
gr.setFont(bigFont);
gr.setColor(newColor);
gr.drawString(companyName, 10, 100);
gr.setColor(Color.magenta);
gr.drawString(companyName, 40, 140);
setBackground(Color.YELLOW);
}


}

Hard - Toiled Teaching

I felt so distressed even when I started my day today. Not only that we had to endure our sleep from the garden tent, we had to wake up early because of the early sunrise. Thus, I feel my eyes falling because I only had few hours of sleep as I read my day's lectures, and did my programming works as sample illustrations before the class.


The toil was more difficult since I kept on anticipating the possibility of being observed by my supervisors. Geez! I am getting unwanted facial zits again. waaaaaaaaaaaaah!!!!  


Pimples and acnes are typical stuffs on people who are always stressed out among other reasons and teaching/schooling can be highly distressing too.  Sometimes, teachers and students ask one another for possible remedy. They try tablets, ointments,  creams, herbs,  and  acne serum   for more effective results.  


It is fulfilling when I teach especially the fun time with my students while learning but the downsides are really uncalled for. These include short sleeps, paper works, emotional stress from failing  and delinquent students,  admin observations, and the list continues.


But, I can only see myself continue teaching even it means doing this in parttime basis only.  This is really an underpaid career but can be fulfilling if I see it in a different perspective.      

Another Java Applet

When an applet is run, it actually executes the initialization method, then goes to start method until one  minimizes/restores, then the applet is stopped, then goes back to start method again. But, when clicks on exit button, then the applet is destroyed and freed from PC's memory.


So, even if we don't write our own applet methods, Java itself calls the default methods and run them. 


See the program below for another applet example.

[+/-] show/hide



/*
* adopted from another java source
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class AppletPartyPlanner extends Applet implements ActionListener {
JLabel companyName = new JLabel ("STI Programs");
JButton calcButton =new JButton("Calculate");
JLabel prompt =new JLabel ("Enter the number of guests at your event: ");
JTextField numGuests = new JTextField(5);
JLabel perPersonResult = new JLabel ("Plan with us.");
JLabel totalResult = new JLabel("The more, the merrier.");
Font bigFont = new Font("Helvetica",Font.BOLD,24);
public void init()
{
companyName.setFont(bigFont);
add(companyName);
add(prompt);
add(numGuests);
add(calcButton);
calcButton.addActionListener(this);
numGuests.addActionListener(this);
add(totalResult);
}
public void start()
{
perPersonResult.setText("Plan with us.");
numGuests.setText("0");
totalResult.setText("The more, the merrier.");
invalidate();
validate();

}

public void actionPerformed(ActionEvent e)
{ int[] guestLimit ={0,25,50,100,200,500,1000};
int[] ratePerGuest ={27,25,22,19,17,14,11};
int guests = Integer.parseInt(numGuests.getText());
int individualFee=0,eventFee=0;
int x=0,a=0;
for (x=5;x>=0;--x)
if(guests>=guestLimit[x])
{ individualFee=ratePerGuest[x];
eventFee=guests * individualFee;
x=0;}
perPersonResult.setText(" $ "+individualFee +" per person");
totalResult.setText("Event cost $"+eventFee);
}

}

Java Applet's Event Handling

One can use event - handling methods in Java's program the same way we write event - method embedded applications. 


So, apart from creating an Applet parent - child relationship, we create the listener interface so that our components may solicit response for every action we do  including but not limited to action buttons or mouse clicks and window movements.


See the program below for a simple illustration of button and labels in an applet.

[+/-] show/hide




/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Rose
*/
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class AppletGreetEvent extends Applet implements ActionListener {
JLabel greeting1 = new JLabel("Hello. Who are you?");
JLabel greeting2 = new JLabel();
Font bigFont = new Font("Times New Roman", Font.ITALIC,24);
JButton pressMe = new JButton("Press Me");
JTextField answer = new JTextField(" ",10);

public void init()
{
add(greeting1);
add(answer);
add(pressMe);
answer.requestFocus();// focus for the textfield
pressMe.addActionListener(this);
add(greeting2);
}

public void start()
{ greeting2.setText("This is a sample applet.");}

public void actionPerformed(ActionEvent thisEvent)
{
String name=answer.getText();

greeting2.setText("Hi "+name);
validate();
}
}

Hazards of Teaching

I had just finished teaching for straight 3 hours and I feel beaten as hell. Teaching is fulfilling but it can actually kill you too (just like any job). Not only that the pay is small but also the papers and student behaviors can add to the burden. Sigh!!!!


But, why do I choose to teach in spite of the decade's underpaid experience? It brings me more than delight to mingle with my students even if they can be that wacky and wild. It brings warmth when I meet them after class and they still recognize and greet me in spite of the time and classroom experience. Further, teaching is a life - long commitment to me.


So, even if I lose my voice and head in teaching, I still love this job. LOL!

Saturday, March 13, 2010

Hot Schooling!

Since end of February, the entire Mindanao has a tremendous ordeal of enduring 12-15 hours of rotating brown outs. This really drives every one crazy especially when businesses become more bleak in sales because customers will not endure very warm and damp area for a transaction.


Now, for residents who have to cut their long sleeps because of interrupted power energy, they can only blame El Nino for the energy curtailment.


In our school, we are only fortunate that we have our power generator to sustain the classroom air conditioning.  Although, sometimes, even if it mans the entire building, it can go astray too sustaining all the power needs. 


Clients and employers can only complain  of this crisis and to make the issue more worse, the energy crisis can run until May. Some say, this is simply a strategy to feign any election fraud. I guess, this country  can only see change in the next life. LOL!


I cannot even use my notebook, much more surf the net for school references and resources or job search      especially if my battery is drained or if the Internet Service Provider is also down. 


Funny thing is, I have been staying in my tent for my evening sleeps since my room is too hot to endure amidst evening brownouts. 


Everything is affected by this crisis that business schedules and alike are drastically changed according to the availability of short - time electricity.


Now, that final examinations are coming, students have to endure too finishing their requirements on time and studying in spite of candle lits only.  

Java Applet's Life Cycle

Any Java Applet goes through four stages: initialization, start, stop and destroy. When an applet is run, it executes initialization once, then proceeds to  start method. However, should we minimize the applet, it stops its execution, then if restored, it goes to execute start again. The destroy method is only run if one chooses to close fully the window.


Find below a sample program to demonstrate the life cycle of an applet. 

[+/-] show/hide



import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class AppletLifeCycle extends Applet implements ActionListener {
Label messageInit = new Label("init ");
Label messageStart = new Label("start ");
Label messageDisplay = new Label("display ");
Label messageAction = new Label("action ");
Label messageStop = new Label("stop ");
Label messageDestroy = new Label("destroy ");
Button pressButton = new Button("Press");

int countInit,countStart,countDisplay,countAction, countStop,countDestroy;

public void init()
{++countInit;
add(messageInit);
add(messageStart);
add(messageDisplay);
add(messageAction);
add(messageStop);
add(messageDestroy);
add(pressButton);
pressButton.addActionListener(this);
display();
}

public void start()
{
++countStart;
display();
}

public void display()
{
++countDisplay;
messageInit.setText("init "+countInit);
messageStart.setText("start "+countStart);
messageDisplay.setText("display "+countDisplay);
messageAction.setText("action "+countAction);
messageStop.setText("stop "+countStop);
messageDestroy.setText("destroy "+countDestroy);

}

public void stop()
{
++countStop;
display();
}
public void destroy()
{
++countDestroy;
display();

}


public void actionPerformed(ActionEvent e)
{
++countAction;
display();
}
}

Saturday, March 6, 2010

Off - School Activities

Today we joined the SOCCSKSARGEN  Bloggers community in their off - town tour through a mining company in the nearby municipality. 


We were joined by other  professional - bloggers and students  - bloggers. The trip was all uphill and the roads were tremendously tricky and scary. In spite of the comfort of our vehicles, we were tossed to all sides of the car because of the rough road at quite treachery speed. 


We even have to joke around if our health and life insurances are updated. One companion was all clinging to his seatbelt and confirmed that he had none of the needed insurances. We did ask him to secure one from  health savings account  to at least make his future more secured.


We were only relieved that when we reached the community base on the peak of one mountain, we were welcomed with a tribal dance and burial site visit. 


The students were pretty amazed by the unique experience from the trip and the distinct practices of the B'laans.


This is one of the trips that I highly favored but it was way too scary too that I kept on thinking of my kid, we chose to leave at home. We headed back to our city all muscles beaten and shaken up.


We are too happy to show off some of our pictures. Forsure, our student - companions would have a lot to share to their classmates and friends.   

Java's Border Layout

A Layout Manager arranges the sizes, location and arrangement of components inside a container. There are six different layouts that can be used. In this post, one useful layout is the border layout. Use this layout if you need five regions of your container: EAST, WEST, NORTH, SOUTH,  and CENTER.


Should only few regions are used, the unused regions shrunk to give space to the used portions. See sample program below to display a container with buttons on the set regions.

[+/-] show/hide



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

public class BorderLayoutDemo extends JFrame{
JButton bN,bS, bE, bW;
Container con = getContentPane();

public BorderLayoutDemo()
{
bN=new JButton("North");
bS=new JButton("Center");
bE=new JButton("East");
bW=new JButton("West");

con.setLayout(new BorderLayout());

con.add(bN,BorderLayout.NORTH);
con.add(bS,BorderLayout.CENTER);
con.add(bE,BorderLayout.EAST);
con.add(bW,BorderLayout.WEST);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main (String [] args){
BorderLayoutDemo frm = new BorderLayoutDemo();
frm.setSize(400,300);
frm.setTitle("Border Layout Demo");
frm.setVisible(true);
}
}

Friday, March 5, 2010

Final Exam Is Up!

We are on the last stretch of school and the entire school is quite busy for the year - end requirements and activities. My old school  is now preparing for the final exam of their graduating students. 


It shall be a difficult time too as students and parents seek means to settle their outstanding accounts while others are already busy seeking for summer and graduation gifts from best deals and sale   from local and global market.


I wish that students shall finish their present semester and school year with decent grades.  And, since this is the final lap, students shall have no other means to improve their performance except to comply everything and ask for teachers' consideration for missed activities.


I shall however, miss my students as we head for vacation time. Although, I am pretty sure, I shall see them around especially in malls. 


So, until this is over, we are all hooked to works and plenty of works.

Java Applets

Applet is different from a typical Java application where it has to work with the Java environment itself. On the other hand, applet must work within another application like an HTML page. Thus, it requires a browser. 


The class name must be the compiled Java program. They are to be of the same location to work. Do check  the needed Java program below.


[+/-] show/hide



import java.applet.*;
import javax.swing.*;

public class AppletGreet1 extends Applet {
JLabel greeting = new JLabel("Hello world");

@Override
public void init()
{

add(greeting);

}

}