I'm trying to store lines of code as an array of strings to use throughout my code, for both readability and quicker writing.
Though I am a newbie to Java, learning this will help a lot in the future. Here is my code:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class GUI extends JFrame {
static Color muis = Color.decode("#433333");
//I set the theme here to use throughout;
public class setFormat {
public String[][] catFormat =
{ { "" , //Button layout(theme) & 0,0 placeholder
"(catFormat[0][0]).setBorderPainted(false)%n;",
"(catFormat[0][0]).setBackground(muis)%n;",
"(catFormat[0][0]).setForeground(Color.WHITE)%n;",
"(catFormat[0][0]).setPreferredSize(new Dimension(151, 35));"}
, { //Menu layout(theme)
"(catFormat[0][0]).setVisible(true)%n;",
"(catFormat[0][0]).setSize(150, 320)%n",
"(catFormat[0][0]).setLayout(new FlowLayout(FlowLayout.RIGHT, 20, 15) );%n",
"(catFormat[0][0]).setResizable(false);%n",
"(catFormat[0][0]).getContentPane().setBackground(muis);%n",
"(catFormat[0][0]).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);%n" }
}; };
public JFrame catmenuf = new JFrame(); {
catmenuf = new JFrame();
setFormat catmenu = new setFormat();
catmenu.catFormat[0][0] = "generalb";
catmenu.catFormat[0][1];
}
final JButton generalb = new JButton("General"); {
setFormat general = new setFormat();
general.catFormat[0][0] = "generalb";
general.catFormat[0][1];
catmenuf.add(generalb);
}
final JButton skillsb = new JButton("Skills"); {
setFormat skills = new setFormat();
skills.catFormat[0][0] = "skillsb";
skills.catFormat[0][1];
catmenuf.add(skillsb);
}
final JButton otherb = new JButton("Other"); {
setFormat other = new setFormat();
other.catFormat[0][0] = "otherb";
other.catFormat[0][1]
catmenuf.add(otherb);
}
public static void main(String[] args) {
new GUI();
}
}
Here are the errors I get:
Eclipse IDE gives me the error:
Syntax error, insert "AssignmentOperator Expression" to complete Expression Google suggests this is a vague error in which the fix varies a lot and depends on the specific circumstances
This is from the line: catmenu.catFormat[0][1]; and every catFormat[0][1]; line onwards
In the "code snippet" tool here on SO I get:
{
"message": "Uncaught SyntaxError: Cannot use import statement outside a module",
"filename": "https://stacksnippets.net/js",
"lineno": 72,
"colno": 9
}
- I don't know what this is though, but I thought it might help a little bit more than what I have from the IDE.
I can't figure this out myself. Any help is appreciated.