Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Java compile error(MyControlProgram is not abstract and does not override abstract..)

    Hi, Ive been struggling to fix this error(MyControlProgram is not abstract and does not override abstract method handleServerString...) in my java program for the past hour, but couldn't find anything It was working uptill now, until I made a few changes. Can anyone notice whats wrong in here???

    import javax.swing.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.net.*;




    public class MyControlProgram implements ActionListener, ServerContract {
    String zz = "MyProgram.";
    static int count = 0; //for the number of clients
    int ThreadNum = 0; //to know which thread is running

    class MyRunnable implements Runnable {


    MyRunnable() {

    }


    public void run() { //creates a new thread

    String sak = "This is client " + (count - 1);

    myClientWindow[count-1] = new MyWindow(sak, true);
    myProgram.tfServer = myClientWindow[count-1].addTextField("server", "Server", null);
    myProgram.tfServer.setText("localhost");
    myProgram.tfPort = myClientWindow[count-1].addTextField("port", "Port Number", null);
    myProgram.tfPort.setText("8080");
    String Sk = "Send String" + (count - 1);
    myProgram.tfText = myClientWindow[count-1].addTextField(Sk, "Text to transmit",myProgram);
    myProgram.tfResult[count-1]=myClientWindow[count-1].addTextField("Result","Result",null);
    myClientWindow[count-1].setBounds(320, 510, 300, 200);
    //System.out.println(myClientWindow.name);


    }


    }

    JTextField tfServerPort = null;

    JTextArea ta = null;
    JTextField tfServer = null;
    JTextField tfPort = null;
    JTextField tfText = null;
    static JTextField tfResult[]; // for every client one referece to the Result text field
    public MyWindow myClientWindow[]; //for every new thread one window
    static MyWindow myServerWindow = null;
    static MyWindow myWindow = null;
    static MyControlProgram myProgram = null;


    static MyRunnable R[];
    static Thread T[];
    static int gir[];


    public static void main(String[] args) {

    // instantiate this class so we have an ActionListener
    myProgram = new MyControlProgram();

    myWindow = new MyWindow("Control", true);
    myWindow.setBounds(310, 10, 200, 300);
    myWindow.addButton("New Server", myProgram);
    myWindow.addButton("New Client", myProgram);

    R = new MyRunnable[25];
    T = new Thread[25];
    gir = new int[25];
    tfResult=new JTextField[25];

    }


    void setupServer() {

    myClientWindow= new MyWindow[25];
    myServerWindow = new MyWindow("This is the server", true);
    myServerWindow.setBounds(10, 10, 200, 300);
    myProgram.tfServerPort =
    myServerWindow.addTextField("port", "Port Number", null);
    myProgram.tfServerPort.setText("8080");
    myServerWindow.addButton("Start Server", myProgram);


    myProgram.ta = myServerWindow.addTextArea("");
    }

    void setupClient() {


    R[count] = new MyRunnable();
    T[count] = new Thread(R[count]);
    T[count].start();
    count++;
    fixRandomNumber(count - 1);


    }


    void sendString(JComponent jc) {
    String z = zz + "sendString ";

    try {
    JTextField tf = (JTextField)jc;
    String mes = tf.getText();
    int port = Integer.parseInt(tfPort.getText());
    String address = tfServer.getText();
    myClientWindow[ThreadNum].sendSocketString(address, port, mes);
    tf.setText("");
    } catch (Exception e) {
    myClientWindow[ThreadNum].log(z + e.toString());
    }
    }


    void stopServer(JComponent jc) {
    JButton b = (JButton)jc;
    MyWindowServer.stopServerSocket();
    b.setText("Start Server");

    }


    void startServer(JComponent jc) {

    JButton b = (JButton)jc;
    int serverPort = Integer.parseInt(tfServerPort.getText());
    MyWindowServer.setupServerSocket(serverPort, this, "server",myServerWindow);
    b.setText("Stop Server");


    }


    public void actionPerformed(ActionEvent ae) {
    String z = zz + "actionPerformed";
    JComponent jc = (JComponent)ae.getSource();
    String action = ae.getActionCommand();

    if ("Start Server".equals(action))
    startServer(jc);
    else if ("Stop Server".equals(action))
    stopServer(jc);
    else {
    for (int i = 0; i < count; i++) {
    String ml = "Send String" + i;
    if (ml.equals(action)) { //logic for finding from which thread the message came from
    ThreadNum = i;

    i = count;
    sendString(jc);

    }

    }
    }

    if ("New Server".equals(action))
    setupServer();
    else if ("New Client".equals(action))
    setupClient();
    else{}
    // myServerWindow.log(z + " could not identify source name = " +
    // action);
    }


    // global int random

    void fixRandomNumber(int m) { //setting up random number for every new client
    double dr = Math.random();
    int ir = (int)(dr * 100.);
    while(!(ir>=50 && ir<=60))
    {
    dr=Math.random();
    ir=(int)(dr*100);
    }
    gir[m]=ir;
    myServerWindow.log("gir =" + gir[m]);
    System.out.println(gir[m]);
    }


    void send(Socket s, String mes) {
    String m = myServerWindow.sendSocketStringReturnResponse(s, mes);

    }

    public void handleServerString(MyWindow myWindow, String commandString,String dataString, Socket s) {
    String z = zz + "handleString ";
    // myServerWindow.log(z + dataString);
    ta.append("\n" +
    dataString);
    try {
    int n = Integer.parseInt(dataString);

    if (n == gir[ThreadNum]) //checking with the appropriate client's random number
    {

    //send(s, "Congratulations, that is correct!");
    myProgram.tfResult[ThreadNum].setText("Congratulations, that is correct!");

    }
    else if (n < gir[ThreadNum]){
    //send(s, "too low!");
    myProgram.tfResult[ThreadNum].setText("Too low");
    }
    else
    {
    // send(s, "too high!");
    myProgram.tfResult[ThreadNum].setText("Too high");


    }


    }


    }


    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    In the future please wrap all code in [php][/php] or [code][/code] tags. Its too hard to read this otherwise.
    Post the interface for ServerContract.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •