Click here to Skip to main content
14,486,704 members
   

Java

 
PinnedForum Guidelines - PLEASE READ PinPopular
Chris Maunder28-Jul-09 2:36
cofounderChris Maunder28-Jul-09 2:36 
Questioncannot resolve Pin
MallardsReach18hrs 5mins ago
MemberMallardsReach18hrs 5mins ago 
AnswerRe: cannot resolve Pin
Richard MacCutchan17hrs 47mins ago
mveRichard MacCutchan17hrs 47mins ago 
GeneralRe: cannot resolve Pin
MallardsReach15hrs 8mins ago
MemberMallardsReach15hrs 8mins ago 
GeneralRe: cannot resolve Pin
Richard MacCutchan14hrs 52mins ago
mveRichard MacCutchan14hrs 52mins ago 
GeneralRe: cannot resolve Pin
MallardsReach11hrs 5mins ago
MemberMallardsReach11hrs 5mins ago 
GeneralRe: cannot resolve Pin
Richard MacCutchan3mins ago
mveRichard MacCutchan3mins ago 
QuestionRadio Button Selected Pin
MallardsReach25-Mar-20 9:50
MemberMallardsReach25-Mar-20 9:50 
QuestionRe: Radio Button Selected Pin
ZurdoDev25-Mar-20 10:10
mveZurdoDev25-Mar-20 10:10 
AnswerRe: Radio Button Selected Pin
MallardsReach25-Mar-20 10:33
MemberMallardsReach25-Mar-20 10:33 
QuestionRe: Radio Button Selected Pin
ZurdoDev25-Mar-20 10:39
mveZurdoDev25-Mar-20 10:39 
AnswerRe: Radio Button Selected Pin
MallardsReach25-Mar-20 11:11
MemberMallardsReach25-Mar-20 11:11 
QuestionRe: Radio Button Selected Pin
ZurdoDev25-Mar-20 12:19
mveZurdoDev25-Mar-20 12:19 
AnswerRe: Radio Button Selected Pin
Richard MacCutchan26-Mar-20 0:16
mveRichard MacCutchan26-Mar-20 0:16 
GeneralRe: Radio Button Selected Pin
MallardsReach26-Mar-20 0:28
MemberMallardsReach26-Mar-20 0:28 
GeneralRe: Radio Button Selected Pin
Richard MacCutchan26-Mar-20 0:36
mveRichard MacCutchan26-Mar-20 0:36 
GeneralRe: Radio Button Selected Pin
MallardsReach26-Mar-20 2:55
MemberMallardsReach26-Mar-20 2:55 
GeneralRe: Radio Button Selected Pin
MallardsReach26-Mar-20 4:15
MemberMallardsReach26-Mar-20 4:15 
QuestionUser defined Method Pin
MallardsReach24-Mar-20 2:56
MemberMallardsReach24-Mar-20 2:56 
Looked at many examples of Method and they all seem easy until I start to place them in my code.
No matter where I insert the method or how I rewrite it I still get a problem.
Below is my Method followed by my code. What am I not doing?
void getSecond(int secondNum){
 displayTable.setText("\n"); //Clear the displayTable
 int firstNum, answerNum;
     for (firstNum = 1; firstNum <=12; firstNum ++){
         answerNum = firstNum * secondNum;
         displayTable.append(firstNum + " x " + secondNum + " = " + answerNum +"\n");
      }


import javax.swing.*;
import java.awt.Color;
import java.awt.Font;
import javax.swing.BorderFactory; 
import javax.swing.border.Border;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyTables
{

	public static void main(String[] args) 
	{
		JFrame frame = new JFrame("Tables"); // Creating instance of JFrame
        frame.setSize(800, 600); // Setting the width and height of frame
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
		JPanel panel = new JPanel(); //Creating panel. Inside panels we can add textfields, buttons and other components.
		panel.setBorder(BorderFactory.createLineBorder(Color.RED));
        frame.add(panel); // Add panel to frame
        placeComponents(panel);  //Call user defined method for adding components to the panel.
		frame.setVisible(true); // Setting the frame visibility to true
    }

	private static void placeComponents(JPanel panel) 
	{
			panel.setLayout(null);
			JTextArea displayTable = new JTextArea("Text Area");
			displayTable.setEditable(false);
			displayTable.setColumns(20);
			displayTable.setFont(new Font("Times New Roman", 1, 14));
			displayTable.setLineWrap(true);
			displayTable.setRows(14);
			displayTable.setWrapStyleWord(true);
			displayTable.setBounds(200,20,230,260); 
			displayTable.setBorder(BorderFactory.createLineBorder(Color.GREEN));
			displayTable.setMaximumSize(new java.awt.Dimension(5, 22));
			panel.add(displayTable);
			
			JLabel userLabel = new JLabel("Enter a Number");  // Creating JLabel
			userLabel.setHorizontalAlignment(SwingConstants.CENTER);
			userLabel.setFont(new Font("Verdana", Font.ITALIC, 16)); //set font
			userLabel.setBounds(10,20,180,25); // Specifies the location and size of component. (x,y,x1,y1)
			userLabel.setBorder(BorderFactory.createLineBorder(Color.BLUE));	
			panel.add(userLabel); // Add Label to panel

			JTextField userText = new JTextField(20); //Create a textfield
			userText.setBounds(10,50,165,25);
			panel.add(userText); // Add TextField to pane

			JButton loginButton = new JButton("Enter"); // Create button
			loginButton.setBounds(10, 80, 80, 25);
			panel.add(loginButton); // Add loginButton to panel
			
			 
		loginButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
				{
					//getSecond(6);
					displayTable.setText("Button Pressed");
				}

		});
    }		
}

AnswerRe: User defined Method Pin
Richard MacCutchan24-Mar-20 4:18
mveRichard MacCutchan24-Mar-20 4:18 
GeneralRe: User defined Method Pin
MallardsReach24-Mar-20 7:39
MemberMallardsReach24-Mar-20 7:39 
GeneralRe: User defined Method Pin
Richard MacCutchan24-Mar-20 7:44
mveRichard MacCutchan24-Mar-20 7:44 
GeneralRe: User defined Method Pin
MallardsReach24-Mar-20 8:29
MemberMallardsReach24-Mar-20 8:29 
GeneralRe: User defined Method Pin
Richard MacCutchan24-Mar-20 10:16
mveRichard MacCutchan24-Mar-20 10:16 
GeneralRe: User defined Method Pin
MallardsReach24-Mar-20 22:17
MemberMallardsReach24-Mar-20 22:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.