I am looking for the most detailed description of how to draw text inside JPanel. I know there are a billion textbooks, but none of them click with me, and I have some specific questions that may help others who are embarrassed. As an installation (test application), I have one class that has JLabel, JTextField, JButton and JPanel. The application reads in ints from an external file and should display the average value in the panel when pressing JButton. I have all the basic program settings (that is, the button responds and prints the average value on the command line), but I just can not figure out how to print the average value on the panel. I think my biggest question is how to include the paint () or paintComponet () method along with the rest of the code. Should he be his own class? Should JPanel be its own class? Most of the textbooks seem to tell me, I'm just not sure what the first step is. The code looks like this:
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Main extends JFrame implements ActionListener { private int[] intArray = new int[10000]; private int numOfInts = 0; private int avg = 0; protected JButton avgBtn; protected JTextField indexEntry; protected JLabel instructions; protected JPanel resultsPanel; public Main(){
Any help / direction is appreciated. I know I recently used this code for other questions, I just want to know everything! Ideally, the panel displays the average reading in ints when the button is pressed and displays everything that was entered in the textfeild when the focus was on it and the click was pressed, but I am taking steps for the child, and, as I said, I would like so that this thread is a general training tool for others with similar questions that do not find answers from solar documents or other sites. Thank you very much in advance. Dan:)
java graphics paint
danwoods
source share