Article View: pl.comp.lang.java
Article #141657pasek narzędzi z JButton
From: mk
Date: Tue, 14 Oct 2008 19:59
Date: Tue, 14 Oct 2008 19:59
92 lines
2847 bytes
2847 bytes
Witam
Mam klasę Menu_Gora gdzie chciałbym zdefiniować 4 przyciski (za
przyciski robiłyby ikonki znajdujące się w folderze ../graf)
To menu z ikonek chciałbym umieścić (wyrównując w pionie: do góry ramki
a w poziomie: do środka) w JFrame.
Idea jest taka aby cała definicja menu z ikonek była w klasie Menu_Gora
i tylko wrzucać je na poszczególne okienka aplikacji.
Dzięki temu jak będzie trzeba coś w menu zmienić, to zmieniam tylko w
jednym miejscu.
Poniżej to co już mam zrobione:
1.
public class RamkaStart extends JFrame
{
public RamkaStart()
{
init();
}
public RamkaStart(String title)
{
super(title);
init();
}
private void init()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
URL file = RamkaStart.class.getResource("ikonka.png");
ImageIcon imageIcon = new ImageIcon(file);
setIconImage(imageIcon.getImage());
setSize(640,480);
setResizable(false);
setLocationRelativeTo( null );
GridBagLayout gbl = new GridBagLayout();
getContentPane().setLayout(gbl);
GridBagConstraints gbc = new GridBagConstraints();
PanelStart panel = new PanelStart();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
getContentPane().add(panel, gbc);
}
}
2.
public class PanelStart extends JPanel
{
private Image aImage = null;
public PanelStart()
{
init();
}
private void init()
{
URL file = PanelStart.class.getResource("tlo.png");
ImageIcon imageIcon = new ImageIcon(file);
aImage = imageIcon.getImage();
}
@Override
public void paint(Graphics g)
{
super.paint(g);
g.drawImage(aImage, 50,50, this);
}
}
3.
public class menu_gora extends JPanel {
ImageIcon PLista = new ImageIcon("lista.png");
JButton b1 = new JButton("Lista", PLista);
}
Prośba o jakiś przykład, to pewnie banalna sprawa ale dopiero się uczę.
dzięki
pozdr.
mk
Technical Details
Message-ID:
<gd2u6s$dah$1@nemesis.news.neostrada.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!wsisiz.edu.pl!newsfeed.neostrada.pl!atlantis.news.neostrada.pl!news.neostrada.pl!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!wsisiz.edu.pl!newsfeed.neostrada.pl!atlantis.news.neostrada.pl!news.neostrada.pl!not-for-mail From: mk <marcinkal@mkintegrator.pl> Newsgroups: pl.comp.lang.java Subject: pasek narzędzi z JButton Date: Tue, 14 Oct 2008 21:59:59 +0200 Organization: TP - http://www.tp.pl/ Lines: 92 Message-ID: <gd2u6s$dah$1@nemesis.news.neostrada.pl> NNTP-Posting-Host: acqi8.neoplus.adsl.tpnet.pl Mime-Version: 1.0 X-Trace: nemesis.news.neostrada.pl 1224014876 13649 83.10.240.8 (14 Oct 2008 20:07:56 GMT) X-Complaints-To: usenet@news.neostrada.pl NNTP-Posting-Date: Tue, 14 Oct 2008 20:07:56 +0000 (UTC) User-Agent: Thunderbird 2.0.0.17 (X11/20080925) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit