Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

JLabel Image. HELP JAVA MASTERS

left4nics

Apprentice
Advanced Member
Messages
51
Reaction score
2
Points
28
Java Masters help naman po. code lng po para makapag lagay ako ng Picture/Image sa GUI ko.
MARAMING SALAMAT SA TUTULONG!

eto po ung gusto ko manyari. dun po mag didisplay ung IMAGE/PICTURE sa color red. 102x102 po size nyan

View attachment 161389

eto po ung code

Code:
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.AbstractButton;
import javax.swing.JCheckBox;
import javax.swing.ImageIcon; 
import javax.imageio.ImageIO;

public class Main extends JFrame {

public JPanel panel;
public JTextField name;
public JTextField cys;
public JTextField stno;
public JTextField gender;
public JTextField address;
public JTextField bday;
public JTextField age;
public JTextField cno;
public JTextField ead;
public JTextField motto;


public Main(){

  
setTitle("INFORMATION");
setResizable(false);
setSize(650,470);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(200,250,200,200);
panel = new JPanel()


{
public void paintComponent(Graphics g) 
{
super.paintComponent(g);				
g.drawImage(new ImageIcon("background.jpg").getImage(), 0, 0, 650, 470, this);
}
public Dimension getPreferredSize() 
{
return new Dimension(650,470);
}
};
setContentPane(panel);
panel.setLayout(null);

stno = new JTextField();
stno.setBounds(45,115,100,25);
stno.setForeground(Color.black);
stno.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
stno.setColumns(10);
panel.add(stno);

name = new JTextField();
name.setBounds(45,170,200,25);
name.setForeground(Color.black);
name.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
name.setColumns(10);
panel.add(name);

cys = new JTextField();
cys.setBounds(45,225,200,25);
cys.setForeground(Color.black);
cys.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
cys.setColumns(10);
panel.add(cys);

address = new JTextField();
address.setBounds(45,280,200,25);
address.setForeground(Color.black);
address.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
address.setColumns(10);
panel.add(address);

bday = new JTextField();
bday.setBounds(45,335,120,25);
bday.setForeground(Color.black);
bday.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
bday.setColumns(10);
panel.add(bday);

age = new JTextField();
age.setBounds(195,335,50,25);
age.setForeground(Color.black);
age.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
age.setColumns(10);
panel.add(age);


JCheckBox male = new JCheckBox("Male");
male.setSelected(true);
male.setBounds(45,390,70,25);
male.setForeground(Color.black);
male.setOpaque(false);
male.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
panel.add(male);
ActionListener amale = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
AbstractButton male = (AbstractButton) actionEvent.getSource();
boolean selected = male.getModel().isSelected();
male.setText("Male");
}
};
   
JCheckBox female = new JCheckBox("Female");
female.setBounds(130,390,70,25);
female.setForeground(Color.black);
female.setOpaque(false);
female.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
panel.add(female);
ActionListener afemale = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
AbstractButton female = (AbstractButton) actionEvent.getSource();
boolean selected = female.getModel().isSelected();
female.setText("Female");
}
};



cno= new JTextField();
cno.setBounds(330,225,200,25);
cno.setForeground(Color.black);
cno.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
cno.setColumns(10);
panel.add(cno);

ead = new JTextField();
ead.setBounds(330,280,200,25);
ead.setForeground(Color.black);
ead.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
ead.setColumns(10);
panel.add(ead);

motto = new JTextField();
motto.setBounds(330,335,200,25);
motto.setForeground(Color.black);
motto.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
motto.setColumns(10);
panel.add(motto);

//LABEL

JLabel lblstno = new JLabel("STUDENT NO.:");
lblstno.setBounds(45,90,135,25);
lblstno.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
lblstno.setForeground(Color.black);
panel.add(lblstno);

JLabel lblname = new JLabel("NAME:");
lblname.setBounds(45,145,150,25);
lblname.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
lblname.setForeground(Color.black);
panel.add(lblname);

JLabel lblcys = new JLabel("COURSE/YEAR/SEC:");
lblcys.setBounds(45,200,150,25);
lblcys.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
lblcys.setForeground(Color.black);
panel.add(lblcys);

JLabel lbladd = new JLabel("ADDRESS:");
lbladd.setBounds(45,255,170,25);
lbladd.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
lbladd.setForeground(Color.black);
panel.add(lbladd);

JLabel lblbday = new JLabel("BIRTHDAY:");
lblbday.setBounds(45,310,135,25);
lblbday.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
lblbday.setForeground(Color.black);
panel.add(lblbday);

JLabel lblage = new JLabel("AGE:");
lblage.setBounds(195,310,135,25);
lblage .setFont(new Font("Comic Sans MS", Font.BOLD, 12));
lblage .setForeground(Color.black);
panel.add(lblage);

JLabel lblgender = new JLabel("GENDER:");
lblgender.setBounds(45,365,135,25);
lblgender.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
lblgender.setForeground(Color.black);
panel.add(lblgender);

JLabel lblcno = new JLabel("CONTACT NO.:");
lblcno.setBounds(330,200,135,25);
lblcno.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
lblcno.setForeground(Color.black);
panel.add(lblcno);

JLabel lblead = new JLabel("EMAIL ADDRESS:");
lblead.setBounds(330,255,135,25);
lblead.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
lblead.setForeground(Color.black);
panel.add(lblead);

JLabel lblmot = new JLabel("MOTTO:");
lblmot.setBounds(330,310,170,25);
lblmot.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
lblmot.setForeground(Color.black);
panel.add(lblmot);

JLabel lblinfo = new JLabel("INFORMATION");
lblinfo.setBounds(20,30,250,30);
lblinfo.setFont(new Font("Georgia", Font.BOLD, 25));
lblinfo.setForeground(Color.darkGray);
panel.add(lblinfo);

JButton cancelbtn = new JButton("CANCEL");
cancelbtn.setBackground(Color.lightGray);
cancelbtn.setForeground(Color.black);
cancelbtn.setBounds(430,430,85,20);
cancelbtn.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
cancelbtn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 
panel.add(cancelbtn);
cancelbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
System.exit(0); 
}
});

JButton loginbtn = new JButton("SUBMIT");
loginbtn.setBackground(Color.lightGray);
loginbtn.setForeground(Color.black);
loginbtn.setBounds(330,430,85,20);
loginbtn.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
loginbtn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 
panel.add(loginbtn);
loginbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {}
});

JButton loginbb = new JButton("BACK");
loginbb.setBackground(Color.lightGray);
loginbb.setForeground(Color.black);
loginbb.setBounds(230,430,85,20);
loginbb.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
loginbb.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
panel.add(loginbb);
loginbb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SearchStudent ss = new SearchStudent();
ss.setVisible(true);
dispose();
}
});


JButton logincc = new JButton("CLEAR");
logincc.setBackground(Color.lightGray);
logincc.setForeground(Color.black);
logincc.setBounds(530,430,85,20);
logincc.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
logincc.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
panel.add(logincc);
logincc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Main cc = new Main();
cc.setVisible(true);
dispose();
}
});
		
pack();
}
public static void main(String[] args)
{
Main ff = new Main();
ff.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ff.setVisible(true);
}
}
 

Attachments

  • HELP.JPG
    HELP.JPG
    47.4 KB · Views: 18
Last edited:
TRY MY CODES AND ALSO EDIT THE GUI IF YOU WANT !!!!

Code:
import java.awt.BorderLayout;
/****AUTHOR BEE !

**********/

public class aw extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField txtDc;
	private JTextField txtNov;
	private JTextField txtAge;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField txtMotto;
	private final JButton btnNewButton = new JButton("BACK");

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					aw frame = new aw();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public aw() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 443, 529);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(85, 107, 47));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblInformation = new JLabel("INFORMATION");
		lblInformation.setFont(new Font("Tahoma", Font.BOLD, 18));
		lblInformation.setHorizontalAlignment(SwingConstants.CENTER);
		lblInformation.setBounds(10, 11, 137, 29);
		contentPane.add(lblInformation);
		
		JLabel lblStudebtId = new JLabel("STUDEBT ID:");
		lblStudebtId.setBounds(44, 59, 64, 22);
		contentPane.add(lblStudebtId);
		
		textField = new JTextField();
		textField.setBounds(33, 86, 86, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel lblName = new JLabel("NAME");
		lblName.setBounds(44, 113, 64, 22);
		contentPane.add(lblName);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(33, 140, 137, 20);
		contentPane.add(textField_1);
		
		JLabel lblCourseyear = new JLabel("COURSE/YEAR/SEC:");
		lblCourseyear.setBounds(44, 171, 98, 22);
		contentPane.add(lblCourseyear);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(33, 193, 137, 20);
		contentPane.add(textField_2);
		
		JLabel lblAddress = new JLabel("ADDRESS:");
		lblAddress.setBounds(44, 224, 98, 22);
		contentPane.add(lblAddress);
		
		txtDc = new JTextField();
		txtDc.setText("DC");
		txtDc.setColumns(10);
		txtDc.setBounds(33, 246, 137, 20);
		contentPane.add(txtDc);
		
		JLabel lblBirthday = new JLabel("BIRTHDAY");
		lblBirthday.setBounds(44, 277, 98, 22);
		contentPane.add(lblBirthday);
		
		txtNov = new JTextField();
		txtNov.setText("NOV 1 1991");
		txtNov.setColumns(10);
		txtNov.setBounds(33, 299, 137, 20);
		contentPane.add(txtNov);
		
		JLabel lblAge = new JLabel("AGE");
		lblAge.setBounds(191, 277, 98, 22);
		contentPane.add(lblAge);
		
		txtAge = new JTextField();
		txtAge.setText("12");
		txtAge.setColumns(10);
		txtAge.setBounds(180, 299, 41, 20);
		contentPane.add(txtAge);
		
		JLabel lblGender = new JLabel("GENDER:");
		lblGender.setBounds(44, 330, 98, 22);
		contentPane.add(lblGender);
		
		JCheckBox chckbxNewCheckBox = new JCheckBox("MALE");
		chckbxNewCheckBox.setBounds(44, 364, 51, 23);
		contentPane.add(chckbxNewCheckBox);
		
		JCheckBox chckbxFemale = new JCheckBox("FEMALE");
		chckbxFemale.setBounds(97, 364, 73, 23);
		contentPane.add(chckbxFemale);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setBounds(280, 193, 137, 20);
		contentPane.add(textField_3);
		
		JLabel lblContactNo = new JLabel("CONTACT NO:");
		lblContactNo.setBounds(291, 171, 98, 22);
		contentPane.add(lblContactNo);
		
		JLabel lblEmailAdd = new JLabel("EMAIL ADD:");
		lblEmailAdd.setBounds(291, 224, 98, 22);
		contentPane.add(lblEmailAdd);
		
		textField_4 = new JTextField();
		textField_4.setColumns(10);
		textField_4.setBounds(280, 246, 137, 20);
		contentPane.add(textField_4);
		
		JLabel lblMotto = new JLabel("MOTTO");
		lblMotto.setBounds(291, 277, 98, 22);
		contentPane.add(lblMotto);
		
		txtMotto = new JTextField();
		txtMotto.setText("MOTTO");
		txtMotto.setColumns(10);
		txtMotto.setBounds(280, 299, 137, 20);
		contentPane.add(txtMotto);
		btnNewButton.setBounds(74, 449, 86, 31);
		contentPane.add(btnNewButton);
		
		JButton btnSubmit = new JButton("SUBMIT");
		btnSubmit.setBounds(158, 449, 86, 31);
		contentPane.add(btnSubmit);
		
		JButton btnCancel = new JButton("CANCEL");
		btnCancel.setBounds(243, 449, 86, 31);
		contentPane.add(btnCancel);
		
		JButton btnClear = new JButton("CLEAR");
		btnClear.setBounds(325, 449, 64, 31);
		contentPane.add(btnClear);
		
		JLabel lblIcon = new JLabel("ICON");//--> ITO YUNG LABEL NA MG LAGAY K NG PICTURES 
		lblIcon.setIcon(new ImageIcon("C:\\Users\\Desktop\\labelbackground\\images.jpg"));
		lblIcon.setBounds(216, 11, 201, 142);
		contentPane.add(lblIcon);
	}
}
 

Attachments

  • SMILE.jpg
    SMILE.jpg
    50 KB · Views: 7
gnito ba ibig mong sabihen?
 

Attachments

  • help.png
    help.png
    257.3 KB · Views: 7
  • help.txt
    8.2 KB · Views: 22
.ung sa image.

.try mo gawing panel ung red na button mo then lagay ka ng panelName.setBackground("imageName.jpg");

ung image mo dapat nkalagay sa parehonh folder ng program mo.. kung gumagamit ka ng jGrasp, kung netbeans naman gawa ka ng bagong package tas import mo sa program mo and then instanciate mo nlang. :) i hope that helped haha :)
 
pahelp naman po sa java netbeans
penge po ako ng full code for this problem:

eto po yung problem:

1st frame ay mag iinput si user ng password then my button "OK"
kapag mali eto output "INCORRECT PASSWORD"
"try 2x" kapag mali ulit "try 1x" kapag mali ulit "wait for 1min."
after 1min pwede kana ulit magtype ng pw
kapag tama ung pw may lalabas na another frame

na my mga button na "DEPOSIT","WITHDRAW","REMAINING BALANCE";


salamat
 
Back
Top Bottom