CyberCodes

Reminders sa mga rehistradong myembro:

•ang lengwahe na gagamitin ay pawang english at tagalog lamang

•Bawal po dito ang pakikipag away

•Bawal ang mga shorcut na mga words
Example: txt, Pwd, at iba pa

•Bawal mababastos at masasakit na salita o anu mang makakasakit
ng damdamin ng isang myembro ng forum na ito

•use the "like" button if the post of the following user you think are usefull


[TUT] Create a Frame in Java with 2 Labels

Go down

Admin Post [TUT] Create a Frame in Java with 2 Labels

Post by princeterror on Sat Jul 21, 2012 2:19 am

making Frame/Form with 2 Labels with color on Java
we should use Eclipse Galileo Language

for main class

Code:
class Main {

   public static void main(String x[])
   {
      new Frame("MY FRAME TEST"); <-------Title ng Frame Naten :D
      
   }
}

for frame class

Code:
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;




class Frame extends JFrame
{
public Frame(String title)
{
   super(title);
   createtxt();
   toplabel();
   initialize();
   
}
public void initialize()
{
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   setSize(600,500);
   setLocationRelativeTo(null);
   setVisible(true);

}


private void createtxt()
{
   JLabel x=new JLabel("THIS IS LABEL 2");
   x.setToolTipText("Label2");
   x.setForeground(Color.MAGENTA);
   add(x,BorderLayout.CENTER);
   x.setHorizontalAlignment(SwingConstants.CENTER);
   
   
}


private void toplabel()
{

   JLabel y=new JLabel("THIS IS LABEL 1");
   y.setToolTipText("Label 1");
   y.setForeground(Color.BLACK);
   add(y,BorderLayout.BEFORE_FIRST_LINE);
   y.setHorizontalAlignment(SwingConstants.CENTER);
}



}
avatar
princeterror
Universal Moderator
Universal Moderator

Posts : 272
Credits : 11465
Fame : 81
Join date : 2012-06-07
Age : 27

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum