我需要帮助,,,我为构建搜索引擎工作 [英] i need help ,,,i work for build search engine
本文介绍了我需要帮助,,,我为构建搜索引擎工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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( 输入你的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 =新JButton( 政治新闻); r1.setLocation( 200 , 200 ); r1.setSize( 150 , 50 );
r2 =新JButton( 医学新闻); r2.setLocation( 400 , 200 ); r2.setSize( 150 , 50 );
r3 =新JButton( 社交新闻); r3.setLocation( 600 , 200 ); r3.setSize( 150 , 50 );
add(myLabel);
add(t);
add(r1);
add(r2);
add(r3);
处理程序处理程序= new Handler();
r1.addActionListener(handler);
r2.addActionListener(handler);
r3.addActionListener(handler);
t.addActionListener(handler);
}
private class 处理程序 implements ActionListener
{
public void actionperformed(ActionEvent事件)
{
if (event.getSource() == t){
}
if (event.getSource()== r1){
}
< span class =code-keyword> if (event.getSource()== r2){
}
if ( event.getSource()== r3){
}
}
}
}
此搜索引擎代码我在src中有包含另外3个文件夹的文件夹
我想构建包含textfield和3按钮的界面,当用户在textfield中文本并点击其中一个按钮时它会打开包含文件的文件夹,,,,我需要3按钮的操作来更改特定文件夹的路径
代码块添加 - OriginalGriff [/ edit]
解决方案
跟进评论:
和我有错误(处理程序)
私有类Handler实现ActionListener
如何解决它?
可能是因为继承的方法被称为action P erformed。
请在此处阅读: ActionListener [ ^ ] @ Java教程
你可以开始通过告诉系统执行Windows文件资源管理器:
尝试 {
Process oProcess = new ProcessBuilder( explorer.exe , / select,C:\\directory \\political)开始(); // 查看\\,反斜杠是一个屏蔽标记,需要屏蔽才能使用normal
// oProcess.waitFor(); //仅当您希望应用程序等待filexplorer完成时
}
catch (异常oException){
oException.printStackTrace(); // 获取完整的异常文字
}
r1.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
reading.read( 政治新闻);
}});
r2.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
reading.read( 经济新闻);
}});
r3.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
reading.read( 社交新闻);
}});
但我无法找到在框架中打印结果
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]
解决方案
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:
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 }
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
这篇关于我需要帮助,,,我为构建搜索引擎工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文