לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 02-05-2015, 14:17
  VansNo1 VansNo1 אינו מחובר  
 
חבר מתאריך: 02.05.15
הודעות: 1
עזרה בנושא Java BorderLayout JButton event

שלום לכולם!
אני סטודנטית טרייה לחלוטין ללימוד שפת תכנות ג'אווה ויש לי פרוייקט הגשה שבו
אני צריכה ליצור חלון על 4 כפתורים BorderLayout
ימין שמאל למעלה למטה
בכל לחיצת כפתור החלון יזוז 20 פיקסל לכיוון המתאים נגיד כפתור שמאל יזיז את החלון 20 פיקסל שמאלה.
עד לנקודה זו ייצרתי את החלון ואת הכפתורים אבל אני לא יודעת איך להפעיל את הכפתורים
in Event Listener
שחייב להיות ב
Inner Class
חובה שזה יהיה עם שיטה שבודקת את גודל הסדקטופ ושלא יהיה אפשר שהחלונית תצא מתווך הדסקטופ
הקוד מצורף בקובץ:

אני אעריך כל עזרה מאוד! https://2015-uploaded.fresh.co.il/2...02/15651593.txt

קוד:
import java.awt.Dimension; import java.awt.BorderLayout; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class WindowBorder extends JFrame { JFrame frame = new JFrame ("Move Window"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); private static final long serialVersionUID = 1L; public WindowBorder (String titel){ super (titel); //create the buttons and the layout and add the buttons JButton right = new JButton ("Right"); JButton left = new JButton ("Left"); JButton up = new JButton ("Up"); JButton down = new JButton ("Down"); //JButton center = new JButton ("Default"); hide the middle button frame.setLayout (new BorderLayout (75,75)); frame.add(BorderLayout.EAST,right); frame.add(BorderLayout.WEST,left); frame.add(BorderLayout.NORTH,up); frame.add(BorderLayout.SOUTH,down); //frame.add(BorderLayout.CENTER,default); hide the middle button //I must create the inner class with the constructors for the task project for school class WindowBorderInner implements ActionListener { @Override public void actionPerformed (ActionEvent e){ if(e.getActionCommand().equals("right")) frame.setLocation ((screenSize.width - getSize().width) + 20, screenSize.height - getSize().height / 0); right.addActionListener(new WindowBorderInner()); if (e.getActionCommand().equals("left")) frame.setLocation ((screenSize.width - getSize().width) - 20, screenSize.height - getSize().height / 0); left.addActionListener(new WindowBorderInner()); if(e.getActionCommand().equals("up")) frame.setLocation ((screenSize.width - getSize().width) / 0, screenSize.height - getSize().height +20); up.addActionListener(new WindowBorderInner()); if (e.getActionCommand().equals("down")) frame.setLocation ((screenSize.width - getSize().width) - 20, screenSize.height - getSize().height - 20); down.addActionListener(new WindowBorderInner()); } } //configuration the size and the location of the Border layout frame.setSize (400,400); //Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocationRelativeTo(null); //frame.setLocation ((screenSize.width - getSize().width)/2, screenSize.height - getSize().height / 2); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E); } public static void main(String [] arg){ //the test method new WindowBorder("Move Window"); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension d = tk.getScreenSize(); System.out.println("Screen width = " + d.width); System.out.println("Screen height = " + d.height); } }

תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 22:53

הדף נוצר ב 0.04 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר