Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.*;
import java.awt .event.ActionListener;
import java.awt .event.ActionEvent;


public class interfac extends JFrame {
	
	
		private JLabel myLabel;private JTextField t;private JButton r1;private JButton r2; private JButton r3;
		private ButtonGroup radioGroup;

	public interfac()
	{
		setTitle("Frame Demo");
		setLocation(100,105); setSize(1000,1000);
		myLabel = new JLabel("ENTER YOUR SEARCH");
		t= new JTextField(50);
		t.setText(" ");
		
		
		setLayout(null);
		myLabel.setLocation(0,0);
		myLabel.setSize(500,300);
		t.setLocation(200,150);
		t.setSize(550,30);
		r1=new JButton("political news");r1.setLocation(200,200);r1.setSize(150,50);
		r2=new JButton("medical news");r2.setLocation(400,200);r2.setSize(150,50);
		r3=new JButton("social news");r3.setLocation(600,200);r3.setSize(150,50);
		add(myLabel);
		add(t);
		
		add(r1);
		add(r2);
		add(r3);
		
		Handler handler=new Handler();
		r1.addActionListener(handler);
		r2.addActionListener(handler);
		r3.addActionListener(handler);
		t.addActionListener(handler);
		

	}
	private class Handler implements ActionListener
	{
		public void actionperformed(ActionEvent event )
		{
			
			
			
		if (event.getSource()==t ){
		}
		if(event.getSource()==r1){
		}
		if(event.getSource()==r2){
		}
		if(event.getSource()==r3){
		}

	
		
		}
	}
	

}



this code for search engine that i have folder in src that contain another 3 folder
and i want to build interface that contain textfield and 3 button , and when the user inter text in textfield and click on one of button it will open the folder that contain documents ,,,, i need the action for the 3 button to change path for the specific folder


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 20-Dec-12 8:30am
v2
Comments
TorstenH. 20-Dec-12 20:44pm    
some suggestions:

- do not call a class interface. That name is taken and specified, you will ruin your day with that.

- Also: class names start with a capital letter: Application

- name your components. t and r1...r3 are not names. call the txtField or btnSearch.


and now some questions:

- what kind of folder? Folder of the OS of the machine you are working on?

- what kind of "path change"?
mss.noor 21-Dec-12 9:49am    
the class name is interfac without "e"

yes folder in my PC
i put folder " myFiles " in my project folder and put into 3 folders
example: myFiles/political


and i have error in (Handler)
private class Handler implements ActionListener
how can solve it?

Follow up to comments:

and i have error in (Handler)
private class Handler implements ActionListener
how can solve it?


probably because the inherited method is called "actionPerformed".

please also read about it here: ActionListener[^] @ the Java Tutorials

You can start the Windows File Explorer by telling the system to do so:

Java
try { 
  Process oProcess = new ProcessBuilder("explorer.exe", "/select,C:\\directory\\political").start();  // check out the "\\", the backslash is a masking tag and needs to be masked to be used "normal"
  // oProcess.waitFor(); // only if you want your app to wait for the filexplorer to finish
}
catch(Exception oException){
  oException.printStackTrace(); // to get full exception text
}
 
Share this answer
 
C#
r1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                reading.read("political news");
            }});
        r2.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                reading.read("economic news");
            }});
        r3.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                reading.read("social news");
            }});


but i cant find away to print result in the frame
 
Share this answer
 
Comments
TorstenH. 22-Dec-12 6:59am    
- Update Component in GUI ( like Label.setText("value");
- call repaint() for region (JPanel/JFrame)
mss.noor 22-Dec-12 7:31am    
but i can't understand how i can get the document after finding similarity from directory vectors
TorstenH. 22-Dec-12 7:43am    
- what kind of document?
- have you searched only on how to read the document? What have you tried?
mss.noor 22-Dec-12 11:32am    
i have many error , because that i can't test the code
but i can read it line by line ,,,it's work

txt file that contain many short of paragraph
like:
d1
....
d2
..
.
.

i want to read it and get similarity with the query that the user enter it in the textfield then the program will display which paragraph(document) that contain this query
TorstenH. 22-Dec-12 15:19pm    
Stringtokenizer
Comparing Strings

or a bit more advanced / more elegant:

You can display HTML in most Java Swing Components: How to Use HTML in Swing Components
Might be useful to present the search results.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900