2 Replies - 476 Views - Last Post: 30 December 2012 - 11:29 AM Rate Topic: -----

#1 SamahAwad  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-December 12

Frame for student

Posted 29 December 2012 - 03:02 PM

*when i pressed on the button which name(Next) (will navigate through all the students saved in the Array List)
*i finished the java application to create a frame.but i want to ask can i solve the problem by use muselistener?



import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.ArrayList; 


public class Student extends JFrame{
	 public JTextField StId=new JTextField(" ");
	 public JTextField StNm=new JTextField(" ");
	 public JTextField StAv=new JTextField(" ");
	 public JButton nt=new JButton("Next");
	public JButton nw=new JButton("New");
    public JButton ad=new JButton("Add");
	 
		Student(){
		JPanel p1=new JPanel(new GridLayout(1,4,20,20));
		p1.add(new JLabel("File Name"));
		p1.add(new JTextField("  "));
		JButton Ld=new JButton("Load");
		p1.add(Ld);
		JButton Se=new JButton("Save");
		p1.add(Se);
		add(p1,BorderLayout.NORTH);
		
		JPanel p2=new JPanel(new GridLayout(4,2,20,20));
		p2.add(new JLabel("Student ID"));
		p2.add(StId);
		p2.add(new JLabel("Student Full Name"));
		p2.add(StNm);
		p2.add(new JLabel("Student Average"));
		p2.add(StAv);
		p2.add(new JLabel("Student Status"));
		p2.add(new JComboBox(new Object[]{"freshman","sophomore","junior","senior"}));
		add(p2,BorderLayout.CENTER);
		
		JPanel p3=new JPanel(new GridLayout(1,4,20,20));
		p3.add(nt);
		p3.add(nw);
        p3.add(ad);
		p3.add(new  JLabel(""));
		add(p3,BorderLayout.SOUTH);
		p3.setBorder(new LineBorder(Color.blue,1));	
		p2.setBorder(new LineBorder(Color.blue,1));	
		p1.setBorder(new LineBorder(Color.blue,1));	
	
		
		nt.addMouseListener(new MouseAdapter(){
		public void mouseClicked(MouseEvent e){
			
			if(e.getClickCount()==1){
				StId.setText("1110188");
				StNm.setText("samah");
				StAv.setText("77.4");
			}else if(e.getClickCount()==2){
				StId.setText("1110155");
				StNm.setText("awad");
				StAv.setText("44");
			}else{
				StId.setText("1145198");
				StNm.setText("fatma");
				StAv.setText("78.6");
			}
			
		}});
	
	
		
		
		
		}

}





import java.awt.*;

import javax.swing.JFrame;
import javax.swing.border.LineBorder;



public class Main {
public static void main(String[] args){
	Student st=new Student();
	st.setTitle("StudentFrame");
	st.setVisible(true);
	st.setLocation(50,50);
	st.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
}
	
	
}



i couldnt attached the photo.

Is This A Good Question/Topic? 0
  • +

Replies To: Frame for student

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Frame for student

Posted 29 December 2012 - 03:12 PM

Don't use a MouseListener over a JButton
A JButton is just a JLabel with a MouseListener and few graphic features that change its shape when clicked
If you want to count the number of click, use a JLabel, make it focusable(true) and add the MouseListener to it
Was This Post Helpful? 1
  • +
  • -

#3 SamahAwad  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-December 12

Re: Frame for student

Posted 30 December 2012 - 11:29 AM

View Postpbl, on 29 December 2012 - 03:12 PM, said:

Don't use a MouseListener over a JButton
A JButton is just a JLabel with a MouseListener and few graphic features that change its shape when clicked
If you want to count the number of click, use a JLabel, make it focusable(true) and add the MouseListener to it


I want to fill Array List contains the name and ID and average
when i clicked on JButton(Next) must Brings me information about other student and so on
i thought by another way to solve the problem
i will stay away from using the Mouse Listener
but if i asking you about:how i can solve it
i think about that all the day but i didnt reach to a true result
I am a beginner
*_*
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1