2017-02-09 11 views
0

私はFacebookのログインページを作成しようとしていて、私が望むイメージをインポートできません。最初にコードを実行すると、作成したすべての機能が表示されますが、画像は表示されませんが、最小化/最大化すると完全にどこに配置するかがわかります。最小化/最大化せずにどのように表示できますか?また、チェックボックスで選択したくない要素がいくつかありますか?Javaのチェックボックスでイメージをインポートしてタイトルを作成するにはどうすればよいですか?

これは私のコードの一部です:あなたのイメージは完全にあなたがのdrawImage(呼び出し時にロードすることはできませんので

import java.awt.*; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import javax.swing.*; 

public class art extends Canvas{ 
public static String emri; 
public static String mbiemri; 
public static JFrame f1; 

public static JButton b9; 
public static JButton b12; 
public static JButton b13; 
public static JButton b15; 
public static JButton b16; 
public static JButton b17; 
public static JButton b18; 
public static JButton b19; 
public static JButton b20; 
public static JButton b21; 
public static JButton b22; 
public static JButton b23; 
public static JButton b24; 
public static JButton b25; 
public static JButton b26; 
public static JButton b27; 
public static JButton b28; 
public static JButton b29; 
public static JButton b30; 
public static JButton b31;; 



public static JComboBox<String> m4; 


public static JTextArea k1; 
public static JTextArea k2; 

public static JFrame f; 
public static JButton b; 
public static JButton a; 
public static JTextArea c; 
public static JTextArea d; 
public static JCheckBox ch; 
public static JTextArea ch1; 
public static JTextArea ch2; 
public static JTextArea ch3; 
public static JTextArea ch4; 
public static JComboBox<String> m; 
public static JComboBox<String> m1; 
public static JComboBox<String> m2; 
public static JComboBox<String> m3; 
public static JButton b1; 
public static JButton b2; 
public static Image p; 
public static Image p1; 
public static Image p2; 
public static Image p3; 
public static Image p4; 
public static Image p5; 

public static JFrame e1; 
public static JFrame e; 
public static JPanel z; 
public static JPanel z1; 
public static JLabel w; 
public static JLabel w1; 
public void paint(Graphics g){ 
    g.setColor(new Color(59, 89, 182)); 
    g.fillRect(0,0 , 1350, 150); 

    g.setColor(new Color(230,230,230)); 
    g.fillRect(0,150 , 1350, 580); 

    g.setColor(Color.white); 
    g.setFont(new Font ("Arial", Font.BOLD, 47)); 
    g.drawString("facebook", 60, 120); 

    g.setColor(Color.white); 
    g.setFont(new Font("Tahoma", Font.BOLD, 13)); 
    g.drawString("Email", 630, 45); 
    g.fillRect(630, 50, 210, 25); 
    g.drawString("Password", 875, 45); 
    g.fillRect(875, 50, 210, 25); 


    g.setFont(new Font("Tahoma", Font.PLAIN, 17)); 
    g.setColor(new Color(59,89,182)); 
    g.drawString("First name:", 700, 320); 
    g.drawLine(800, 300, 1100, 300); 
    g.drawLine(800, 300, 800, 330); 
    g.drawLine(800, 330, 1100, 330); 
    g.drawLine(1100, 300, 1100, 330); 

    g.drawString("Last name:", 700, 355); 
    g.drawLine(800, 335, 1100, 335); 
    g.drawLine(800, 335, 800, 365); 
    g.drawLine(800, 365, 1100, 365); 
    g.drawLine(1100, 335, 1100, 365); 

    g.drawString("Your Email:", 700, 390); 
    g.drawLine(800, 370, 1100, 370); 
    g.drawLine(800, 370, 800, 400); 
    g.drawLine(800, 400, 1100, 400); 
    g.drawLine(1100, 370, 1100, 400); 


    g.drawString("New Password:", 670, 425); 
    g.drawLine(800, 405, 1100, 405); 
    g.drawLine(800, 405, 800, 435); 
    g.drawLine(800, 435, 1100, 435); 
    g.drawLine(1100, 405, 1100, 435); 

    g.drawString("I am:", 745, 460); 
    g.drawString("Birthday:", 720, 495); 

    g.setColor(new Color(59, 89, 182)); 
    g.setFont(new Font("Luciana Grande",Font.BOLD, 20)); 
    g.drawString("Sign UP", 600, 250); 
    g.drawString("Facebook helps you connect and share with", 60, 240); 
    g.drawString("the people in your life.", 60, 270); 


    g.setFont(new Font("Luciana Grande",Font.PLAIN, 20)); 
    g.drawString("it's free (and alwyas will be)",600, 280); 

    g.setColor(new Color(59,89,192)); 
    g.drawLine(630, 605, 1250, 605); 
    g.drawString("Create a page", 710, 630); 

    g.setColor(Color.LIGHT_GRAY); 
    g.drawString("for a celebrity, band or business.",843, 630); 

    g.drawImage(p, 60, 330, 400, 170, null); 
} 


public static void main(String[] args) { 
    art x = new art(); 
    f = new JFrame(); 
    f1= new JFrame(); 
    e= new JFrame(); 
    e1= new JFrame(); 
    b = new JButton(); 
    a = new JButton(); 
    b1 = new JButton(); 
    b2 = new JButton(); 
    b9= new JButton(); 
    b12= new JButton(); 
    b13 = new JButton(); 
    b15 = new JButton(); 
    b16 = new JButton(); 
    b17 = new JButton(); 
    b18 = new JButton(); 
    b19 = new JButton(); 
    b20 = new JButton(); 
    b21 = new JButton(); 
    b22 = new JButton(); 
    b23 = new JButton(); 
    b23 = new JButton(); 
    b24 = new JButton(); 
    b25 = new JButton(); 
    b26 = new JButton(); 
    b27 = new JButton(); 
    b28 = new JButton(); 
    b29 = new JButton(); 
    b30 = new JButton(); 
    b31 = new JButton(); 

    c= new JTextArea(); 
    d= new JTextArea(); 
    ch= new JCheckBox();  
    ch1= new JTextArea(); 
    ch2= new JTextArea(); 
    ch3= new JTextArea(); 
    ch4= new JTextArea(); 
    k1= new JTextArea(); 
    k2 = new JTextArea(); 

    m1= new JComboBox<String>(); 
    m= new JComboBox<String>(); 
    m2=new JComboBox<String>(); 
    m3=new JComboBox<String>(); 
    m4= new JComboBox<String>(); 


    z= new JPanel(); 
    z1= new JPanel(); 
    w= new JLabel(); 
    w1= new JLabel(); 

    p = Toolkit.getDefaultToolkit().createImage("image.jpeg"); 

    m4.addItem("Friends"); 
    m4.addItem("Only me"); 
    m4.addItem("Everyone"); 




    m1.addItem("Month:"); 
    m1.addItem("January"); 
    m1.addItem("February"); 
    m1.addItem("March"); 
    m1.addItem("April"); 
    m1.addItem("May"); 
    m1.addItem("June"); 
    m1.addItem("July"); 
    m1.addItem("September"); 
    m1.addItem("October"); 
    m1.addItem("November"); 
    m1.addItem("December"); 
    m1.addItemListener(null); 
    m1.setBounds(800,477, 83,20); 

    m2.addItem("Day:"); 
    m2.addItem("1"); 
    m2.addItem("2"); 
    m2.addItem("3"); 
    m2.addItem("4"); 
    m2.addItem("5"); 
    m2.addItem("6"); 
    m2.addItem("7"); 
    m2.addItem("8"); 
    m2.addItem("9"); 
    m2.addItem("10"); 
    m2.addItem("11"); 
    m2.addItem("12"); 
    m2.addItem("13"); 
    m2.addItem("14"); 
    m2.addItem("15"); 
    m2.addItem("16"); 
    m2.addItem("17"); 
    m2.addItem("18"); 
    m2.addItem("19"); 
    m2.addItem("20"); 
    m2.addItem("21"); 
    m2.addItem("22"); 
    m2.addItem("23"); 
    m2.addItem("24"); 
    m2.addItem("25"); 
    m2.addItem("26"); 
    m2.addItem("27"); 
    m2.addItem("28"); 
    m2.addItem("29"); 
    m2.addItem("30"); 
    m2.addItemListener(null); 
    m2.setBounds(900, 477, 50, 20); 

    m3.addItem("Year:"); 
    m3.addItem("2017"); 
    m3.addItem("2016"); 
    m3.addItem("2015"); 
    m3.addItem("2014"); 
    m3.addItem("2013"); 
    m3.addItem("2012"); 
    m3.addItem("2011"); 
    m3.addItem("2010"); 
    m3.addItem("2009"); 
    m3.addItem("2008"); 
    m3.addItem("2007"); 
    m3.addItem("2006"); 
    m3.addItem("2005"); 
    m3.addItem("2004"); 
    m3.addItem("2003"); 
    m3.addItem("2002"); 
    m3.addItem("2001"); 
    m3.addItem("2000"); 
    m3.addItem("1999"); 
    m3.addItem("1998"); 
    m3.addItem("1997"); 
    m3.addItem("1996"); 
    m3.addItem("1995"); 
    m3.addItem("1994"); 
    m3.addItem("1993"); 
    m3.addItem("1992"); 
    m3.addItem("1991"); 
    m3.addItem("1990"); 
    m3.addItem("1900"); 
    m3.addItemListener(null); 
    m3.setBounds(970, 477, 60, 20); 

    m.addItem("Select sex:"); 
    m.addItem("Male"); 
    m.addItem("Female"); 
    m.addItemListener(null); 
    m.setBounds(800, 445, 90, 20); 

    a.setText("Forgot your password?"); 
    a.setBackground(new Color(59, 89, 182)); 
    a.setForeground(Color.white); 
    a.setBounds(875, 103, 200, 20); 

    b.setText("login"); 
    b.setBackground(new Color(59, 89, 182)); 
    b.setForeground(Color.white); 
    b.setFocusPainted(true); 
    b.setFont(new Font("Tahoma", Font.BOLD, 13)); 
    b.setBounds(1120, 49, 100, 25); 
    b.addActionListener(new ActionListener(){ 
     @Override 
     public void actionPerformed(ActionEvent e){ 
      String v1=JOptionPane.showInputDialog(null, "Vendosni emrin:"); 
      emri= new String(v1).toString(); 
      String v2= JOptionPane.showInputDialog(null, "Vendosni mbiemrin:"); 
      mbiemri= new String(v2).toString(); 
      b9.setBounds(400, 400, 50, 40); 

      m4.setBackground(new Color(230,230,230)); 
      m4.setForeground(new Color(59,89,18)); 
      m4.setBounds(420, 268, 100, 30); 


      b23.setBackground(new Color(59,89,182)); 
      b23.setForeground(Color.WHITE); 
      b23.setText("Post"); 
      b23.setBounds(525, 268, 89, 30); 

      b24.setBackground(new Color(230,230,230)); 
      b24.setForeground(new Color(59,89,18)); 
      b24.setText("Search"); 
      b24.setBounds(525, 30, 99, 30); 

      b25.setBackground(new Color(230,230,230)); 
      b25.setForeground(new Color(59,89,18)); 
      b25.setText("Send Friend Request"); 
      b25.setBounds(730, 250, 180, 30); 

      b26.setBackground(new Color(230,230,230)); 
      b26.setForeground(new Color(59,89,18)); 
      b26.setText("Like"); 
      b26.setBounds(730, 430, 60, 30); 

      b27.setBackground(new Color(230,230,230)); 
      b27.setForeground(new Color(59,89,18)); 
      b27.setText("Join"); 
      b27.setBounds(730, 620, 60, 30); 

      b28.setBackground(new Color(230,230,230)); 
      b28.setForeground(new Color(59,89,18)); 
      b28.setText("Chat(230)"); 
      b28.setBounds(1100, 648, 200, 30); 

      b29.setBackground(new Color(230,230,230)); 
      b29.setForeground(new Color(59,89,18)); 
      b29.setText("Like"); 
      b29.setBounds(250, 630, 70, 20); 
      b30.setBackground(new Color(230,230,230)); 
      b30.setForeground(new Color(59,89,18)); 
      b30.setText("Comment"); 
      b30.setBounds(321, 630, 95, 20); 
      b31.setBackground(new Color(230,230,230)); 
      b31.setForeground(new Color(59,89,18)); 
      b31.setText("Share"); 
      b31.setBounds(402, 630, 70, 20); 

      artvazhdim a = new artvazhdim(); 

      k1.setBounds(131, 32, 200, 20); 
      k2.setBounds(192, 185, 200, 30); 

      b17.setBackground(new Color(230,230,230)); 
      b17.setForeground(new Color(59,89,18)); 
      b17.setText(emri + " " +mbiemri); 
      b17.setBounds(18, 108, 160, 30); 

      b18.setBackground(new Color(230,230,230)); 
      b18.setForeground(new Color(59,89,18)); 
      b18.setText("News Feed"); 
      b18.setBounds(18, 145, 100, 20); 

      b19.setBackground(new Color(230,230,230)); 
      b19.setForeground(new Color(59,89,18)); 
      b19.setText("Messages"); 
      b19.setBounds(18, 172, 105, 20); 

      b20.setBackground(new Color(230,230,230)); 
      b20.setForeground(new Color(59,89,18)); 
      b20.setText("Groups"); 
      b20.setBounds(18, 295, 80, 20); 

      b21.setBackground(new Color(230,230,230)); 
      b21.setForeground(new Color(59,89,18)); 
      b21.setText("Friend Lists"); 
      b21.setBounds(18, 330, 120, 20); 

      b22.setBackground(new Color(230,230,230)); 
      b22.setForeground(new Color(59,89,18)); 
      b22.setText("Pokes"); 
      b22.setBounds(18, 365, 80, 20); 


      f1.getContentPane().add(a); 
      b9.setBackground(new Color(59,89,182)); 
      b9.setForeground(Color.white); 
      b9.setBounds(899, 30, 100, 30); 
      b9.setText(emri); 
      b12.setBackground(new Color(59,89,182)); 
      b12.setForeground(Color.white); 
      b12.setText("Profile"); 
      b12.setBounds(1004, 30, 80, 30); 
      b13.setBackground(new Color(59,89,182)); 
      b13.setForeground(Color.white); 
      b13.setText("logout"); 
      b13.setBounds(1088, 30, 70, 30); 
      b13.addActionListener(new ActionListener(){ 
       @Override 
       public void actionPerformed(ActionEvent k){ 
        f1.setVisible(false); 
        f.setVisible(true); 

       } 

      }); 
      b15.setBackground(new Color(230,230,230)); 
      b15.setForeground(new Color(59,89,18)); 
      b15.setText("Photo/video"); 
      b15.setFont(new Font("Tahoma",Font.BOLD,9)); 
      b15.setBounds(198, 145, 100, 20); 

      b16.setBackground(new Color(230,230,230)); 
      b16.setForeground(new Color(59,89,18)); 
      b16.setText("Photo/video Album"); 
      b16.setBounds(303, 145, 100, 20); 


      f1.add(m4); 
      f1.add(b19); 
      f1.add(b20); 
      f1.add(b21); 
      f1.add(b24); 
      f1.add(b22); 
      f1.add(b28); 
      f1.add(b16); 
      f1.add(b30); 
      f1.add(b31); 
      f1.add(b17); 
      f1.add(b13); 
      f1.add(b23); 
      f1.add(b25); 
      f1.add(b29); 
      f1.add(b26); 
      f1.add(b27); 
      f1.add(b15); 
      f1.add(b12); 
      f1.add(b9); 
      f1.add(k1); 
      f1.add(b18); 
      f1.add(k2); 
      f1.add(a); 
      f1.setSize(1350, 720); 



      f1.setVisible(true); 
      f.setVisible(false); 

     } 

    }); 




    b1.setText("Why do i need to provide this?"); 
    b1.setBackground(new Color(230,230,230)); 
    b1.setForeground(new Color(59,89,182)); 
    b1.setFont(new Font("Tahoma", Font.BOLD, 13)); 
    b1.setBounds(800, 500, 270, 35); 

    b2.setFont(new Font("Tahoma", Font.BOLD, 16)); 
    b2.setText("Sign up"); 
    b2.addActionListener(new ActionListener(){ 
     @Override 
     public void actionPerformed(ActionEvent args0){ 
      z1.setBackground(new Color(59,89,182)); 
      w1.setText("Congratulations, you are the newest member on Facebook!!"); 
      w1.setForeground(Color.white); 
      w1.setFont(new Font("Tahoma",Font.BOLD,30)); 
      w1.setBounds(200,100,1000,200); 
      e1.add(w1); 

      e1.add(z1); 
      e1.setSize(1350,720); 
      e1.setVisible(true); 


     } 
    }); 
    b2.setBackground(Color.green); 
    b2.setForeground(Color.WHITE); 
    b2.setBounds(800, 560, 100, 40); 

    c.setBounds(631, 54, 208, 20); 
    ch1.setBackground(new Color(230,230,230)); 
    ch2.setBackground(new Color(230,230,230)); 
    ch3.setBackground(new Color(230,230,230)); 
    ch4.setBackground(new Color(230,230,230)); 
    ch1.setBounds(801, 307, 299, 22); 
    ch2.setBounds(801, 342, 299, 22); 
    ch3.setBounds(801, 377, 299, 22); 
    ch4.setBounds(801, 412, 299, 22); 

    d.setBounds(876, 54, 208, 20); 

    ch.setBounds(626, 76, 135 , 70); 
    ch.setText("Keep me logged in"); 
    ch.setForeground(Color.WHITE); 
    ch.setBackground(new Color(59, 89, 182)); 

    f.setSize(1350, 720); 
    f.repaint(); 
    f.revalidate(); 


    f.add(b2); 
    f.add(b1); 
    f.add(m3); 
    f.add(m2); 
    f.add(m1); 
    f.add(m); 
    f.add(ch2); 
    f.add(ch3); 
    f.add(ch4); 
    f.add(ch1); 
    f.add(a); 
    f.add(ch); 
    f.add(d); 
    f.add(c); 
    f.add(b); 
    f.add(x); 

    f.setVisible(true); 

} 

} 
+0

[mcve]の作成方法をお読みください。 –

答えて

0

Toolkit.createImage())は、非同期です。

g.drawImage(p, 60, 330, 400, 170, this); 

か(できれ)のローディングイメージのImageIOでを使用するには:また

p = ImageIO.read(new File("image.jpeg")); 

、あなたはAWT(キャンバス)とSwingコンポーネントを混在させるべきではありませんあなたはImageObserverのを提供するために、いずれかが必要です。実際には、AWTをまったく使用しないでください(古くて重い)。代わりにJPanelを使用して描画します。

関連する問題