Click here to Skip to main content
16,016,306 members
Home / Discussions / Java
   

Java

 
AnswerRe: Radio Button Selected Pin
MallardsReach25-Mar-20 11:11
MallardsReach25-Mar-20 11:11 
QuestionRe: Radio Button Selected Pin
ZurdoDev25-Mar-20 12:19
professionalZurdoDev25-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
MallardsReach26-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
MallardsReach26-Mar-20 2:55 
GeneralRe: Radio Button Selected Pin
MallardsReach26-Mar-20 4:15
MallardsReach26-Mar-20 4:15 
QuestionUser defined Method Pin
MallardsReach24-Mar-20 2:56
MallardsReach24-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?
Java
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");
      }


Java
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
MallardsReach24-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
MallardsReach24-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
MallardsReach24-Mar-20 22:17 
QuestionJTextArea Pin
MallardsReach23-Mar-20 0:48
MallardsReach23-Mar-20 0:48 
AnswerRe: JTextArea Pin
Richard MacCutchan23-Mar-20 0:54
mveRichard MacCutchan23-Mar-20 0:54 
QuestionCalling a Method at run time Pin
MallardsReach21-Mar-20 22:32
MallardsReach21-Mar-20 22:32 
AnswerRe: Calling a Method at run time Pin
Richard MacCutchan21-Mar-20 23:29
mveRichard MacCutchan21-Mar-20 23:29 
GeneralRe: Calling a Method at run time Pin
MallardsReach22-Mar-20 0:38
MallardsReach22-Mar-20 0:38 
GeneralRe: Calling a Method at run time Pin
Richard MacCutchan22-Mar-20 0:48
mveRichard MacCutchan22-Mar-20 0:48 
GeneralRe: Calling a Method at run time Pin
MallardsReach22-Mar-20 1:08
MallardsReach22-Mar-20 1:08 
GeneralRe: Calling a Method at run time Pin
Richard MacCutchan22-Mar-20 4:08
mveRichard MacCutchan22-Mar-20 4:08 
GeneralRe: Calling a Method at run time Pin
MallardsReach22-Mar-20 6:00
MallardsReach22-Mar-20 6:00 
QuestionMouse Dragged Event Pin
MallardsReach18-Mar-20 11:15
MallardsReach18-Mar-20 11:15 
AnswerRe: Mouse Dragged Event Pin
Richard MacCutchan18-Mar-20 21:47
mveRichard MacCutchan18-Mar-20 21:47 

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.