Results 1 to 3 of 3
Thread: JscrollBar not working
- 12-14-2012, 12:29 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 1
- Rep Power
- 0
JscrollBar not working
Hi, i'm new to Java and i have this exercise to make.
The purpose is to enter a number in the inputfield and the code has to process the input in order to multiply it incrementaly 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;
}
}
- 12-14-2012, 02:41 PM #2
Re: JscrollBar not working
Please go through Guide For New Members and BB Code List - Java Programming Forum and edit your post accordingly.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-14-2012, 02:44 PM #3
Re: JscrollBar not working
Read the API for JScrollPane and follow the link to the Swing tutorial on How to Use Scroll Panes. Just constructing one and setting its location doesn't do anything to the components that you have actually added to the GUI hierarchy.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
JScrollbar not working
By Tastosis in forum New To JavaReplies: 7Last Post: 03-22-2011, 06:22 AM -
paint with JScrollBar
By shakeel in forum Java 2DReplies: 5Last Post: 12-23-2010, 04:35 PM -
Problem with JScrollBar
By Arthur in forum AWT / SwingReplies: 3Last Post: 02-19-2010, 02:59 AM -
A problem with JScrollBar and the Jbutton
By cowboy in forum New To JavaReplies: 5Last Post: 12-19-2009, 09:17 PM -
JScrollBar
By solomon_13000 in forum AWT / SwingReplies: 1Last Post: 07-01-2009, 07:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks