📄 JB_164_JavaCodingQuestion.java .java dosyası

⬇️ İndir
import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.SwingConstants; public class JB_164_JavaCodingQuestion { public static void main(String[] args) { JFrame frame = new JFrame("Java Coding Question | Java Blackboard [164]"); frame.setLayout(null); JPanel anaPanel = new JPanel(); anaPanel.setLayout(null); anaPanel.setBackground(new Color(54, 79, 89)); anaPanel.setBounds(20, 20, 960, 425); JLabel labelArray = new JLabel(); labelArray.setText("int[] intDizi = {2, 1, 0};"); labelArray.setFont(new Font("Ubuntu Mono", Font.BOLD, 35)); labelArray.setForeground(new Color(242, 230, 206)); labelArray.setHorizontalAlignment(SwingConstants.LEFT); labelArray.setBounds(50, 30, 700, 40); JLabel labelForLine_1 = new JLabel(); labelForLine_1.setText("for (int i : intDizi) {"); labelForLine_1.setFont(new Font("Ubuntu Mono", Font.BOLD, 35)); labelForLine_1.setForeground(new Color(242, 230, 206)); labelForLine_1.setHorizontalAlignment(SwingConstants.LEFT); labelForLine_1.setBounds(50, 80, 700, 40); JLabel labelForLine_2 = new JLabel(); labelForLine_2.setText("System.out.println(intDizi[i]);"); labelForLine_2.setFont(new Font("Ubuntu Mono", Font.BOLD, 35)); labelForLine_2.setForeground(new Color(242, 230, 206)); labelForLine_2.setHorizontalAlignment(SwingConstants.LEFT); labelForLine_2.setBounds(120, 130, 700, 40); JLabel labelForLine_3 = new JLabel(); labelForLine_3.setText("}"); labelForLine_3.setFont(new Font("Ubuntu Mono", Font.BOLD, 35)); labelForLine_3.setForeground(new Color(242, 230, 206)); labelForLine_3.setHorizontalAlignment(SwingConstants.LEFT); labelForLine_3.setBounds(50, 180, 700, 40); JButton butonShow = new JButton("Show the solution"); butonShow.setFont(new Font("Ubuntu Mono", Font.BOLD, 25)); butonShow.setBounds(50, 230, 300, 40); JTextArea taSolution = new JTextArea(); taSolution.setBounds(50, 280, 900, 500); taSolution.setFont(new Font("Ubuntu Mono", Font.PLAIN, 35)); taSolution.setForeground(new Color(242, 230, 206)); taSolution.setBackground(new Color(54, 79, 89)); taSolution.setEditable(false); // Butona tıklama olayı butonShow.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Diziyi tanımla int[] intDizi = {2, 1, 0}; // TextArea'yı temizle taSolution.setText(""); // For döngüsü ile sonuçları yazdır for (int i : intDizi) { taSolution.append(intDizi[i] + " // intDizi[i] -> intDizi["+i+"]\n"); } } }); frame.add(anaPanel); anaPanel.add(labelArray); anaPanel.add(labelForLine_1); anaPanel.add(labelForLine_2); anaPanel.add(labelForLine_3); anaPanel.add(butonShow); anaPanel.add(taSolution); frame.setSize(1000, 500); frame.setLocationRelativeTo(null); frame.getContentPane().setBackground(new Color(163, 178, 191)); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }