T
terrestrex
Gast
Guten Tag,
ich habe ein Progrämmchen geschrieben um den PC automatisch nach eine gewisse Zeit runterzufahren.
(Es ist kein Hexenwerk: Ich benutze die EXE- Shutdown von Windoof )
Das Problem, das ich jetzt habe ist, dass die JMenuItems von den Komponenten, die sich unter der Menuleiste befinden, verdeckt werden.
Da ich mir das GUI so vorstelle, dass es wie ein Collage funktioniert, habe ich versucht die Menuleiste (der Klasse JMenuBar) mit mehrere Panels hervorzuheben - ohne Erfolg :cry:
Ich komme einfach nicht weiter und wäre für jede Hilfe dankbar.
Gruß
Hier mein Code für das Fenster
Damit es Funktioniert muss diese Klasse auch eingefügt werden:
[/code]
ich habe ein Progrämmchen geschrieben um den PC automatisch nach eine gewisse Zeit runterzufahren.
(Es ist kein Hexenwerk: Ich benutze die EXE- Shutdown von Windoof )
Das Problem, das ich jetzt habe ist, dass die JMenuItems von den Komponenten, die sich unter der Menuleiste befinden, verdeckt werden.
Da ich mir das GUI so vorstelle, dass es wie ein Collage funktioniert, habe ich versucht die Menuleiste (der Klasse JMenuBar) mit mehrere Panels hervorzuheben - ohne Erfolg :cry:
Ich komme einfach nicht weiter und wäre für jede Hilfe dankbar.
Gruß
Hier mein Code für das Fenster
Code:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Rahmen implements ActionListener{
/****************** globale variablen*************************/
private int minute, hour, day, month, year;
private GregorianCalendar theDateNow = new GregorianCalendar();
private Date theDate = new Date(theDateNow.getTimeInMillis()); //heutiges Datum
private TextField theYearField,theMonthField,theDayField,theHourField,theMinuteField;
private static final long serialVersionUID = 12;
private String Comment_text = "Shutdown initialisert mit Shutdown for WinXP";
private int wid; //pixelbreite des bildschirms
private int hig; //pixelhoehe des Bildschirms
private JPanel thePanel = new JPanel();
private JFrame theFrame; //Rahmen des Fensters
//private JPanel theBarPanel; //Panel für den BarMenu
private Point thePosition;
private int[] FrameSize = new int[4];
///////////Konstruktor
public Rahmen()
{
wid = Toolkit.getDefaultToolkit().getScreenSize().width;
hig = Toolkit.getDefaultToolkit().getScreenSize().height;
theFrame = new JFrame("Shutdown for WinXP");
ImageIcon icon = new ImageIcon("shutdown.png");
theFrame.setIconImage(icon.getImage());
theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //programm schließen
theFrame.setContentPane(getPanel()); //dasFenster//das frame bekommt dieses fensterobjekt
theFrame.pack();
//theFrame.setSize(wid/2,160); //framegroesse zuweisen
//theFrame.setLocation(wid/4,hig/2-160); //position des fensters
theFrame.setVisible(true); //es wird alles sichtbar
}
/////////////thePanel
public JPanel getPanel()
{
String theYear = String.valueOf(theDateNow.get(theDateNow.YEAR)); //diese Jahr
int theMonth0 = theDateNow.get(theDateNow.MONTH); //in java werden die monate von 0 - 12 gezaehlt
String theMonth = String.valueOf(theMonth0+1); //diese Monat
String theDay = String.valueOf(theDateNow.get(theDateNow.DAY_OF_MONTH));//diese Jahr
String theHour = String.valueOf(theDateNow.get(theDateNow.HOUR_OF_DAY));//jetzige Stunde
String theMinute = String.valueOf(theDateNow.get(theDateNow.MINUTE)); //jetzige minute
int littleMinute = theDateNow.get(theDateNow.MINUTE); //Damit die Uhr nicht 12:6 anzeigt
if(littleMinute<10){theMinute="0"+theMinute;} //...sondern 12:06
/*****************Panel allgemein*****************/
thePanel.setBackground(new Color(120,170,120));
thePanel.setLayout(new BorderLayout());
/*************************************************/
/*****************CENTER********************/
JPanel theCenterPanel = new JPanel();
theCenterPanel.setLayout(new GridLayout(2,1));
JPanel theTimePanel = new JPanel();
theTimePanel.setSize(wid/2,20);
theTimePanel.setLayout(new FlowLayout());
theYearField = new TextField(theYear);
theMonthField = new TextField(theMonth);
theDayField = new TextField(theDay);
theHourField = new TextField(theHour);
theMinuteField = new TextField(theMinute);
theTimePanel.add(new Label(sprache.Shutdown_at));
theTimePanel.add(theHourField);
theTimePanel.add(new Label(":"));
theTimePanel.add(theMinuteField);
theTimePanel.add(new Label(sprache.at));
theTimePanel.add(theDayField);
theTimePanel.add(new Label("."));
theTimePanel.add(theMonthField);
theTimePanel.add(new Label(".",Label.LEFT));
theTimePanel.add(theYearField);
JPanel theButtonPanel_1 = new JPanel();
theButtonPanel_1.setSize(wid/2,20);
theButtonPanel_1.setLayout(new FlowLayout());
JPanel theButtonPanel_2 = new JPanel();
theButtonPanel_2.setSize(wid/2,20);
theButtonPanel_2.setLayout(new FlowLayout());
JPanel theButtonPanel = new JPanel();
theButtonPanel.setSize(wid/2,20);
theButtonPanel.setLayout(new GridLayout(2,1));
JButton theShutdownButton = new JButton(sprache.shutdown);
theShutdownButton.addActionListener(this);
JButton theShutdownBreakButton = new JButton(sprache.shutdownbreak);
theShutdownBreakButton.addActionListener(this);
JButton theCommentButton = new JButton(sprache.comment);
theCommentButton.addActionListener(this);
JButton theButtonEnd = new JButton(sprache.END);
theButtonEnd.addActionListener(this);
theButtonPanel_1.add(theShutdownButton);
theButtonPanel_1.add(theShutdownBreakButton);
theButtonPanel_1.add(theCommentButton);
theButtonPanel_2.add(theButtonEnd);
theButtonPanel.add(theButtonPanel_1);
theButtonPanel.add(theButtonPanel_2);
theCenterPanel.add(theTimePanel);
theCenterPanel.add(theButtonPanel);
thePanel.add(theCenterPanel, BorderLayout.CENTER);
/**************NORTH****************/
JMenuBar theBar = new JMenuBar();
JMenu theFiles = new JMenu(sprache.files);
JMenu theOption = new JMenu(sprache.options);
JMenu theHelp = new JMenu(sprache.help);
JMenuItem theItemEnd = new JMenuItem(sprache.END);
theItemEnd.addActionListener(this);
JMenuItem theCommentItem = new JMenuItem(sprache.comment);
theCommentItem.addActionListener(this);
theFiles.add(theItemEnd);
theOption.add(theCommentItem);
JMenuItem theInfoItem = new JMenuItem(sprache.info);
theInfoItem.addActionListener(this);
theHelp.add(theInfoItem);
theBar.add(theFiles);
theBar.add(theOption); //wird später noch gebraucht
theBar.add(theHelp);
/*JPanel theBarPanel2 = new JPanel();
JPanel theBarPanel = new JPanel();
JPanel theBarPanel3 = new JPanel();
JPanel theBarPanel4 = new JPanel();
theBarPanel2.add(theBar);
theBarPanel3.add(theBarPanel2);
theBarPanel4.add(theBarPanel3);
theBarPanel.add(theBarPanel4);
theBarPanel = new JPanel();
theBarPanel.add(theBar);*/
thePanel.add(theBar, BorderLayout.NORTH);
/***********************************************/
return thePanel;
}
.....
.....
.....
}
Damit es Funktioniert muss diese Klasse auch eingefügt werden:
Code:
public class sprache {
public static final String END = new String("Programm beenden");
public static final String shutdown = new String("Runterfahren");
public static final String shutdownbreak = new String("Runterfahren abbrechen");
public static final String no_date = new String("Das ist kein gueltiges Datum");
public static final String at = new String(" am");
public static final String Shutdown_at = new String("Herunterfahren um");
public static final String lenguage = new String("Sprache");
public static final String options = new String("Optionen");
public static final String files = new String("Datei");
public static final String comment = new String("Kommentar einfügen");
public static final String no_comment = new String("Kommentar verwerfen");
public static final String long_comment = new String("bitte max. 255 Zeichen");
public static final String no_valid_time = new String("Das System kann nur in der Zukunft runtergefahren werden!");
public static final String info = new String("über das Programm");
public static final String vers = new String("Vers. 0.5.1");
public static final String ok = new String("ok!");
public static final String theInformation = new String("von ***** in Liebe für ******!");
public static final String help = new String("Hilfe");
public static final String about = new String("über...");
[/code]