Expand|Select|Wrap|Line Numbers
- package zad41;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.*;
- import java.net.*;
- import javax.swing.BorderFactory;
- import javax.swing.BoxLayout;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- public class SimpleClient {
- public static void main(String[] args) throws IOException {
- PhoneDirectory phonedirectory = new PhoneDirectory("numbers.txt");
- String action=null;
- JButton search = new JButton("Wyszukaj");
- JButton add = new JButton("Dodaj");
- JButton replace = new JButton("Zastap");
- JButton bye = new JButton("Bye");
- JTextField add_name = new JTextField(20);
- JTextField replace_with = new JTextField(20);
- JTextField output = new JTextField(20);
- JComboBox namesList1 = new JComboBox(phonedirectory.getNames());
- JComboBox namesList2 = new JComboBox(phonedirectory.getNames());
- Socket kkSocket = null;
- PrintWriter out = null;
- BufferedReader in = null;
- JPanel pane = new JPanel();
- JLabel label1 = new JLabel("Wyszukaj");
- JLabel label2 = new JLabel("Dodaj");
- JLabel label3 = new JLabel("Zastap");
- pane.setBorder(BorderFactory.createTitledBorder("Client"));
- pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
- pane.add(label1);
- pane.add(namesList1);
- pane.add(search);
- pane.add(label2);
- pane.add(add_name);
- pane.add(add);
- pane.add(label3);
- pane.add(replace_with);
- pane.add(namesList2);
- pane.add(replace);
- pane.add(output);
- output.setEditable(false);
- JFrame frame = new JFrame("Client");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- // /final Table table = new Table();
- frame.setContentPane(pane);
- frame.pack();
- // /f.setLocationRelativeTo(null);
- frame.setVisible(true);
- try {
- kkSocket = new Socket("localhost", 4444);
- out = new PrintWriter(kkSocket.getOutputStream(), true);
- in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
- } catch (UnknownHostException e) {
- System.err.println("Don't know about host: localhost.");
- System.exit(1);
- } catch (IOException e) {
- System.err.println("Couldn't get I/O for the connection to: localhost.");
- System.exit(1);
- }
- BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
- String fromServer;
- String lastname;
- search.addActionListener( new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- action="get";
- lastname=(String)namesList1.getSelectedItem();
- }
- });
- while ((fromServer = in.readLine()) != null) {
- System.out.println("Server: " + fromServer);
- if (fromServer.equals("Bye."))
- break;
- ////fromUser = stdIn.readLine();
- if (action != null) {
- System.out.println("Client: " + action);
- out.println(action);
- }
- }
- out.close();
- in.close();
- stdIn.close();
- kkSocket.close();
- }
- }
why eclipse highlights
action="get";
lastname=(String)namesList1.getSelectedItem as an error
and says to change action variable to final ?