analog via jssc to java swing slider

im connected a poti to my arduino.

now i want to control with the poti an slider on my java gui

but i dont know how i should do this.

does someone have a examle.

but i dont know how i should do this.

Serial.print(someValue);

The rest is up to your PC code to deal with. Those questions belong in Interfacing with Software on the PC, not here.

this is my source code

Arduino

String message;
int stat;

void setup()
{  
pinMode(13, OUTPUT);
   
Serial.begin(9600); }

void loop(void)
{

while(Serial.available())
{
  message+=char(Serial.read());
  if(!Serial.available())
    {
      Serial.println(message);
      stat =message.toInt();
      message = "";
    }
 
if(stat == 1){ 

digitalWrite(13, HIGH);
}
}if(stat == 0)
{
    digitalWrite(13, LOW);
}}

but i no idee where and what i should write for my analog value

this is my java code where i want to controll the slider

/**
 * Package : AA_Serial
 * Projekt : AA_Seriell MF
 * 
 * Author : Martin Fricker
 * FTE 2
 * 02.01.2016. 
 * 14:04:54
 *
 */
package AA_Serial;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import jssc.SerialPort;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import jssc.SerialPortException;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import jssc.SerialPort;
import jssc.SerialPortEvent;
import jssc.SerialPortException;
import jssc.SerialPortList;


public class AA_Serial
{
	public JFrame frame;
	private String[] portNames;
	private static SerialPort serialPort;
	private JComboBox<String> comboBox;
	private String cmboitem;
	private JLabel lbl1;

	/**
	 * * Launch the application.
	 * */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AA_Serial window = new AA_Serial();
					window.frame.setVisible(true);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			});
		}
	public AA_Serial() 
		{
		this.portNames = SerialPortList.getPortNames();
		initialize();
		}
		/**
		* Initialize the contents of the frame.
		*/
	
	
	private void initialize() 
		{
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		
		// Position Button
		JButton btnEin = new JButton("Ein");
		btnEin.setBounds(43, 136, 89, 23);
		frame.getContentPane().add(btnEin);
		
		JButton btnAus = new JButton("Aus");
		btnAus.setBounds(43, 170, 89, 23);
		frame.getContentPane().add(btnAus);
		
		// Position Slider
		JSlider slider = new JSlider();

	    slider.setMinimum(0);   		  //stellt den Minimalwert auf 0 ein
	    slider.setMaximum(265);			  //stellt den Maximalwert auf 150 ein
	    slider.setValue(0);    			 //Anfangswert 
	    
	    slider.setMinorTickSpacing(50);   //Abstände im Feinraster
	    slider.setMajorTickSpacing(50);  //Abstände im Großraster
	  
	    slider.setPaintTicks(true);  	// Raster
	    slider.setPaintLabels(true);    // Zahlen Beschriftung
	   
	    slider.setExtent(10);			  //der Zeiger verspringt jedesmal 10Einheiten
		slider.setBounds(43, 45, 273, 50);
		frame.getContentPane().add(slider);
		
		//Position Label
		JTextPane txtpnStatusAnalog = new JTextPane();
		txtpnStatusAnalog.setText("    Status Analog");
		txtpnStatusAnalog.setBounds(322, 45, 102, 26);
		frame.getContentPane().add(txtpnStatusAnalog);
		
		JTextPane txtpnStatusDigital = new JTextPane();
		txtpnStatusDigital.setText("     Status Digital");
		txtpnStatusDigital.setBounds(322, 126, 102, 20);
		frame.getContentPane().add(txtpnStatusDigital);
		
		lbl1 = new JLabel("");
		lbl1.setBounds(322, 200, 100, 23);
		frame.getContentPane().add(lbl1);
		
		JLabel lblcopy = new JLabel("\u00A9 Martin Fricker 2015 \u00A9");
		lblcopy.setBounds(290, 236, 134, 14);
		frame.getContentPane().add(lblcopy);
		
		
		comboBox = new JComboBox<String>();
		for(int i = 0; i < this.portNames.length; i++)
		{
		comboBox.addItem(this.portNames[i]);
		}
		comboBox.addActionListener(new ActionListener() {
		
			
			
			public void actionPerformed(ActionEvent arg0) {
		//Com Port auswählen
		
				cmboitem = (String) comboBox.getSelectedItem();
				System.out.println(cmboitem);
		
				try 
				{
					serialPort = new SerialPort(cmboitem);
					serialPort.openPort();
					serialPort.setParams(9600, 8, 1, 0);//Sezen der Parameter
					lbl1.setText(cmboitem +" ist offen");
				} 
				catch (SerialPortException e) 
				{
		// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			});
		
		comboBox.setBounds(322, 170, 100, 20);
		frame.getContentPane().add(comboBox);
		
		
		//Button EIN
		btnEin.addActionListener(new ActionListener() 
		{
		public void actionPerformed(ActionEvent e) 
		{
		
			try 
			{
		
				if(serialPort!=null)
				{
		
					serialPort.writeBytes("1".getBytes());
					txtpnStatusDigital.setBackground(Color.GREEN);
					txtpnStatusDigital.setText("1");
		}
				else 
		{
		
					lbl1.setText("kein COM Port ausgewählt");
		}
		} 
			catch (SerialPortException e1) {
		}
		}
		});
		
		//Button Aus
		btnAus.addActionListener(new ActionListener() 
		{
		public void actionPerformed(ActionEvent e) 
		{
		
			try 
			{
		
				if(serialPort!=null){
				serialPort.writeBytes("0".getBytes());
				txtpnStatusDigital.setBackground(Color.RED);
				txtpnStatusDigital.setText("0");
			}
				else 
				{
		
					lbl1.setText("kein COM Port ausgewählt");
				}
			} 
			catch (SerialPortException e1) 
			{
			}
		}
		});
		
	      {
		      slider.addChangeListener(new ChangeListener() {
			      public void stateChanged(ChangeEvent e) {
			    	 int analogWert = slider.getValue();
			    	 txtpnStatusAnalog.setText(""+analogWert);
			      }
			    });
		      
		      
			    frame.add(slider);
	      }

		      
		}
}

frickerm:
but i no idee where and what i should write for my analog value

The Arduino code you posted seems more concerned with receiving data rather than sending it. For receiving have a look at the examples in Serial Input Basics. They are simple reliable ways to receive data. The 3rd example will be most reliable.

You can use the same technique as in the 3rd example to send data to the PC. For example

Serial.print('<');
Serial.print(potValue);
Serial.println('>');

and then you can write your Java code to expect that format.

In this Python - Arduino demo there is also a JRuby version of the PC code. JRuby uses the JVM and I think I was using JSSC when I wrote it.

…R