buildConstraints(gbcl1, 0, 5, 1, 1, 100, 100);
Linie line2 = new Linie();
gbll1.setConstraints(line2, gbcl1);
panellinks1.add(line2);
class Linie extends JPanel
{
public void paintComponent(Graphics linie){
int x1 = ((getSize().width) / 2);
int x2 = ((getSize().width) * 2);
int y = ((getSize().height) / 2);
linie.drawLine(x1, y, x2, y);
}
}
class Linie extends JPanel
{
public void paintComponent(Graphics graph){
Graphics2D graph2D = (Graphics2D)graph;
graph2D.draw(new Line2D.Float(new Point2D.Float(0, 0), new Point2D.Float(this.getSize().width, 0)));
}
}
class NeueLinie extends JPanel
{
public void paintComponent(Graphics graph){
Graphics2D graph2D = (Graphics2D)graph;
graph2D.draw(new Line2D.Float(new Point2D.Float(0, 0), new Point2D.Float(this.getSize().width, 0)));
graph2D.setColor(Color.BLACK);
}
}
public class Kalender extends JFrame{
Kalender(){
super("Kalender");
setSize(1024, 768);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setExtendedState(MAXIMIZED_BOTH);
JPanel hauptpanel = new JPanel();
hauptpanel.setLayout(new GridLayout(1, 4));
JPanel panellinks = new JPanel();
panellinks.setLayout(new GridLayout(2, 1));
JPanel panellinks1 = new JPanel();
GridBagLayout gbll1 = new GridBagLayout();
GridBagConstraints gbcl1 = new GridBagConstraints();
panellinks1.setLayout(gbll1);
// leeres Label
buildConstraints(gbcl1, 0, 0, 1, 1, 100, 100);
JLabel leer1 = new JLabel("");
gbll1.setConstraints(leer1, gbcl1);
panellinks1.add(leer1);
// Notizen Label
buildConstraints(gbcl1, 0, 1, 1, 1, 100, 100);
JLabel notizenL = new JLabel();
notizenL.setText("Notizen");
notizenL.setFont(new Font("Monospaced", Font.PLAIN, 11));
notizenL.setForeground(Color.BLUE.darker());
gbll1.setConstraints(notizenL, gbcl1);
panellinks1.add(notizenL);
// Notizen TextArea
buildConstraints(gbcl1, 0, 2, 1, 3, 100, 100);
JTextArea notizenT = getNotizen();
JScrollPane scroll = new JScrollPane(notizenT);
scroll.setPreferredSize(new Dimension(220, 90));
notizenT.setRows(5);
notizenT.setColumns(20);
notizenT.setCaretColor(Color.RED);
notizenT.setFont(new Font("SansSerif", Font.PLAIN, 13));
notizenT.setToolTipText("Hier können Sie Ihre Notizen eingeben");
notizenT.setLineWrap(true);
notizenT.setWrapStyleWord(true);
notizenT.setVisible(true);
gbll1.setConstraints(scroll, gbcl1);
panellinks1.add(scroll);
// leer
buildConstraints(gbcl1, 0, 5, 1, 1, 100, 100);
NeueLinie line1 = new NeueLinie();
line1.setSize(getPreferredSize());
gbll1.setConstraints(line1, gbcl1);
panellinks1.add(line1);
// Wochentag Label
buildConstraints(gbcl1, 0, 6, 1, 1, 100, 100);
JLabel wochentag = new JLabel();
wochentag.setText(Zeit.getDayOfWeek());
wochentag.setFont(new Font("SansSerif", Font.ITALIC, 20));
wochentag.setToolTipText("Heute ist "+Zeit.getDayOfWeek());
gbll1.setConstraints(wochentag, gbcl1);
panellinks1.add(wochentag);
// Datum Label
buildConstraints(gbcl1, 0, 7, 1, 1, 100, 100);
JLabel datum = new JLabel();
datum.setText(Zeit.getDayOfMonth() + "." + Zeit.getMonth() + "." + Zeit.getYear());
datum.setFont(new Font("SansSerif", Font.ITALIC, 20));
datum.setToolTipText("Heute ist der " + Zeit.getDayOfMonth() + "." + Zeit.getMonth());
gbll1.setConstraints(datum, gbcl1);
panellinks1.add(datum);
// leer
buildConstraints(gbcl1, 0, 8, 1, 1, 100, 100);
Linie line2 = new Linie();
line2.setSize(getPreferredSize());
gbll1.setConstraints(line2, gbcl1);
panellinks1.add(line2);
JPanel panellinks2 = new JPanel();
GridBagLayout gbll2 = new GridBagLayout();
GridBagConstraints gbcl2 = new GridBagConstraints();
panellinks.add(panellinks1);
panellinks.add(panellinks2);
hauptpanel.add(panellinks);
hauptpanel.add(new JPanel());
hauptpanel.add(new JPanel());
hauptpanel.add(new JPanel());
setContentPane(hauptpanel);
setVisible(true);
}
void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy){
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
}
private JTextArea getNotizen(){
File notizenF = new File("Kalender" + File.separator + "notizen.txt");
if(notizenF.exists()){
try{
StringBuffer buffer = new StringBuffer();
BufferedReader in = new BufferedReader(new FileReader(notizenF));
for (String b;(b = in.readLine()) != null;buffer.append(b));
return new JTextArea(buffer.toString());
}
catch(Exception exc){
return new JTextArea("Datei konnte nicht gelesen werden");
}
}
else{
return new JTextArea("Notizen\nHier können Sie Ihre Notizen eingeben\nSie werden beim nächsten Start wieder angezeigt");
}
}
}
Unterklasse von JLabel!!!!! Wie ich schon gesagt hab machst du grad immer unterklasse von JPanel!!Roar hat gesagt.:unterklasse von JLabel schrieben, paintCoomponent() überschreiben - linie malen - suchfunktion benutzen :-/
class NeueLinie extends JPanel
buildConstraints(gbcl1, 0, 5, 1, 1, 100, 100);
Linie line1 = new Linie();
line1.setText(" ");
gbll1.setConstraints(line1, gbcl1);
panellinks1.add(line1);