My JText Area is not working. You will see if you run this code. The textArea keeps going to different places even though I have set a definitive spot that it should be. The code for the textArea is line 57.
What I exactly need is for the testArea to maintain a fixed position, which is explained in line 57.
Note: 'pain' is a JPanel containing the textArea
public Graphics g;
public void paint(Graphics g) {
Graphics2D projectFinder = (Graphics2D) g;
projectFinder.setColor(Color.GRAY);
projectFinder.fillRect(0, 0, 1000, 50);
projectFinder.setStroke(new BasicStroke(100));
Graphics2D OutPut = (Graphics2D) g;
OutPut.setColor(Color.LIGHT_GRAY);
OutPut.fillRect(553, 60, 535, 670);
OutPut.drawString("Project Input (Your Code)", 30, 90);
Graphics2D console = (Graphics2D) g;
console.setColor(Color.WHITE);
console.fillRect(563, 620, 515, 100);
console.setColor(Color.BLACK);
console.drawString("Console.ChemLOG", 570, 640);
}
public static void main(String[] args) {
JPanel pnlButton = new JPanel();
pnlButton.setBounds(800, 100, 100, 100);
JButton button = new JButton("Add Project");
button.setBounds(1000, 0, 100, 50);
JFrame frame = new JFrame("GenoTECH IDE 1.0.0");
frame.add(new MainScreen());
frame.setSize(1100, 800);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(button);
button.addActionListener(new NewProject());
// TextBox
JPanel pain = new JPanel();
JTextArea area = new JTextArea();
area.setSize(535, 670);
area.setLocation(0, 0);
pain.setLocation(10, 60);
pain.setSize(area.getSize());
pain.add(area);
frame.add(pain);
}
// add project button
static class NewProject implements ActionListener {
public void actionPerformed(ActionEvent e) {
JButton buttonOK = new JButton("Ok");
buttonOK.setBounds(0, 233, 150, 45);
JButton buttonCn = new JButton("Cancel");
buttonCn.setBounds(150, 233, 150, 45);
JFrame frame2 = new JFrame("New Project");
frame2.setSize(300, 300);
frame2.setVisible(true);
frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame2.add(buttonOK);
frame2.add(buttonCn);
buttonCn.addActionListener(new buttonCN());
}
static class buttonCN implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
}
}
Ok now for an update for the code, I have got the JTextArea to work without messing up, however the 2D graphics is not getting called for some reason. I am also working on another layout using some of the Java layout formats.
New Code:
private static final long serialVersionUID = 1L;
public Graphics g;
public void paint(Graphics g) {
Graphics2D projectFinder = (Graphics2D) g;
projectFinder.setColor(Color.GRAY);
projectFinder.fillRect(0, 0, 1000, 50);
projectFinder.setStroke(new BasicStroke(100));
Graphics2D OutPut = (Graphics2D) g;
OutPut.setColor(Color.LIGHT_GRAY);
OutPut.fillRect(553, 60, 535, 670);
OutPut.drawString("Project Input (Your Code)", 30, 90);
Graphics2D console = (Graphics2D) g;
console.setColor(Color.WHITE);
console.fillRect(563, 620, 515, 100);
console.setColor(Color.BLACK);
console.drawString("Console.ChemLOG", 570, 640);
}
public static void main(String[] args) {
JButton button = new JButton("Add Project");
button.setBounds(1000, 0, 100, 50);
//button.setSize(5,5);
//button.setLocation(1,1);
JFrame frame = new JFrame("GenoTECH IDE 1.0.0");
frame.setLayout(null);
frame.add(new MainScreen());
frame.setSize(1100, 800);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(button);
button.addActionListener(new NewProject());
// Thing to Change
JTextArea area = new JTextArea();
area.setSize(535, 670);
area.setLocation(10, 60);
frame.add(area);
}
// add project button
static class NewProject implements ActionListener {
public void actionPerformed(ActionEvent e) {
JButton buttonOK = new JButton("Ok");
buttonOK.setBounds(0, 233, 150, 45);
JButton buttonCn = new JButton("Cancel");
buttonCn.setBounds(150, 233, 150, 45);
JFrame frame2 = new JFrame("New Project");
frame2.setSize(300, 300);
frame2.setVisible(true);
frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame2.add(buttonOK);
frame2.add(buttonCn);
}
}