Java - Ayuda con variables

 
Vista:

Ayuda con variables

Publicado por Pedro Cristos (1 intervención) el 05/06/2021 00:18:59
Tengo un problema con las variable, quiero gestionar las fotos (con la variable foto) para que con el botón avanzar y retroceder cambiar una foto (ya que son muchas fotos y están numeradas del 1 al 66) pero me aparecen estos errores:

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at paqueteJava.VentanaInicial.<init>(VentanaInicial.java:126)
at paqueteJava.VentanaInicial.main(VentanaInicial.java:176)


No se que hacer. Por cierto mi profesor de TIC enseña fatal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package paqueteJava;
import javax.swing.*;
 
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
public class VentanaInicial {
	JFrame ventanaInicio= new JFrame("Ce 78 App");
	//Inicio
	JLabel titulo= new JLabel();
	JLabel autor= new JLabel();
	JLabel articulo= new JLabel();
	JButton botApuntes=new JButton();
	JButton botExamen=new JButton();
	JButton botInfo=new JButton();
	JPanel Inicio= new JPanel();
	JPanel marPrincipalTituloAutor= new JPanel();
	JPanel marPrincipalBotones= new JPanel();
	JPanel marBotones= new JPanel();
	JPanel marBotones1= new JPanel();
	JPanel marArticulo= new JPanel();
	JPanel Espacio= new JPanel();
	JPanel marTitulo= new JPanel();
	JPanel marAutor= new JPanel();
	JPanel marInfo= new JPanel();
	Font fuente = new Font("Arial",1,13);
	String texto;
	//Apuntes
	JButton Volver=new JButton();
	JButton Avanzar=new JButton();
	JLabel Foto= new JLabel();
	JPanel Apuntes= new JPanel();
	JPanel marControl= new JPanel();
	JPanel marFoto= new JPanel();
	double resultado=1;
	double foto=0;
	double uno=1;
	public VentanaInicial() {
		//Características
		ventanaInicio.setPreferredSize(new Dimension(1200,900));
		ventanaInicio.setExtendedState(ventanaInicio.MAXIMIZED_BOTH);
		ventanaInicio.setMinimumSize(ventanaInicio.getPreferredSize());
		ventanaInicio.setLocationRelativeTo(null);
		ventanaInicio.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//ventanaInicio.setBounds(800,800,700,700);
 
		titulo.setText("Ce 78 App");
		titulo.setFont(new Font("Arial",3,60));
		titulo.setForeground(Color.BLACK);
		titulo.setHorizontalAlignment(JTextField.CENTER);
		titulo.setHorizontalAlignment(Label.RIGHT);
 
		autor.setText("Por Pedro Cristos Martinez");
		autor.setFont(new Font("Arial",0,20));
		autor.setForeground(Color.BLACK);
		autor.setHorizontalAlignment(JTextField.CENTER);
 
		texto="<html><body><br><br><br>DON JUAN CARLOS I</body></html>";
		articulo.setText(texto);
		articulo.setFont(fuente);
 
 
		botExamen.setIcon(new ImageIcon(getClass().getResource("Aceptar.gif")));
		botExamen.setText("Acceso a examen");
		botExamen.setPreferredSize(new Dimension (200,40));
		botExamen.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
 
		Inicio.setVisible(false);
		//ventanaInicio.add();
 
 
 
 
		}
		}
		);
		//Examen
 
		botApuntes.setIcon(new ImageIcon(getClass().getResource("Derecha.gif")));
		botApuntes.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
		botApuntes.setText("Acceso a apuntes");
		botApuntes.setPreferredSize(new Dimension (200,40));
		botApuntes.addActionListener( new ActionListener(){
		public void actionPerformed(ActionEvent e){
 
			Inicio.setVisible(false);
			ventanaInicio.add(Apuntes);
			Foto.setIcon(new ImageIcon(getClass().getResource("25.png")));
 
 
 
			}
			}
			);
		//Apuntes
		Volver.setIcon(new ImageIcon(getClass().getResource("Izquierda.gif")));
		Volver.setText("Volver al menu");
		Volver.setPreferredSize(new Dimension (200,40));
		Volver.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			foto=resultado-uno;
 
 
			}
			}
			);
 
 
		Avanzar.setIcon(new ImageIcon(getClass().getResource("Derecha.gif")));
		Avanzar.setText("Siguiente lección");
		Avanzar.setPreferredSize(new Dimension (200,40));
		Avanzar.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
 
			foto=resultado+uno;
 
			//if (foto>=)
 
			}
			}
			);
 
		Foto.setHorizontalAlignment(JTextField.CENTER);
		Foto.setIcon(new ImageIcon(getClass().getResource(foto+".png")));
 
		//botInfo.setIcon(new ImageIcon(getClass().getResource("")));
		botInfo.setText("Info");
		botInfo.setPreferredSize(new Dimension (80,40));
		//botInfo.addActionListener( new ());
 
 
		//Montaje INICIO:
		marBotones.setLayout(new BorderLayout());
		marBotones.add("Center",botApuntes);
		marBotones.add("South",botExamen);
		marBotones1.setLayout(new FlowLayout(FlowLayout.LEFT));
		marBotones1.add(marBotones);
		marTitulo.setLayout(new FlowLayout(FlowLayout.LEFT));
		marTitulo.add(titulo,("Sup.1"));
		marInfo.setLayout(new BorderLayout());
		marInfo.add("South",botInfo);
		marArticulo.add(articulo);
		marAutor.setLayout(new FlowLayout(FlowLayout.LEFT));
		marAutor.add(autor);
		marPrincipalTituloAutor.setLayout(new BorderLayout());
		marPrincipalTituloAutor.add("Center",marTitulo);
		marPrincipalTituloAutor.add("South",marAutor);
		marPrincipalBotones.add(marBotones1);
		marPrincipalBotones.add(marArticulo);
		marPrincipalBotones.add(marInfo);
		Inicio.setLayout(new BorderLayout());
		Inicio.setBorder(BorderFactory.createEmptyBorder(2,30,20,20));
		Inicio.add("North",marPrincipalTituloAutor);
		Inicio.add("Center",marArticulo);
		Inicio.add("South",marPrincipalBotones);
		ventanaInicio.add(Inicio);
		ventanaInicio.setResizable(true);
		ventanaInicio.setVisible(true);
		//Montaje
		marControl.setLayout(new FlowLayout(FlowLayout.CENTER));
		marControl.add(Volver);
		marControl.add(Espacio);
		marControl.add(Avanzar);
		marFoto.add(Foto);
		Apuntes.setBorder(BorderFactory.createEmptyBorder(2,30,20,20));
		Apuntes.setLayout(new BorderLayout());
		Apuntes.add("North",marControl);
		Apuntes.add("Center",marFoto);
 
 
 
	}
	public static void main(String[] args) {
		new VentanaInicial();
 
		}
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder