Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

JscrollBar not working

$
0
0
Hi, i'm new to Java and i received this exercise.
The purpose is to enter a number in the inputfield and the code has to multiply this number 100 times (for loop)and finally displaying a list tha tlooks like :
0x10 = 0
1x10 = 10
2x10 = 20
3x10 = 30 ect...
So we need a scrollBar since the frame is to small to containt the entire output.
Please copy and paste my code and help me fix this.

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

class Rekenen extends JFrame {
	private JTextField inputField = new JTextField(4);
	JScrollPane spane;
	private JLabel output = new JLabel();
	static int result;

	public static void main(String[] args) {
		Rekenen window = new Rekenen();
		window.setSize(300, 300);
		window.setVisible(true);
	}

	public Rekenen() {
		// Create button and add action listener.

		JButton berekenButton = new JButton("Compute");
		spane = new JScrollPane();
		berekenButton.addActionListener(new Listener());

		// Set layout and add components.
		JPanel content = new JPanel();
		content.setLayout(new FlowLayout());
		content.add(berekenButton);
		content.add(inputField);
		content.add(output);
		// Set the window characteristics.

		content.setBackground(Color.BLACK);
		setContentPane(content);
		setTitle("RekenApp");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		spane.setLocation(0, 35);
		setLocationRelativeTo(null); // Center window.
	}
	private class Listener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			int cijfer = (int) Double.parseDouble(inputField.getText());

			int berekening = (int) computeCijfer(cijfer);

			output.setText(result);

		}
	}

	public static double computeCijfer(int cijfer) {

		for (int i = 0; i < 100; i++) {
			int result = cijfer * i;

		}

		return result;

	}
}


Please :code:

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>