کاملا طبیعیه که این طوری بشه چون شما clock رو دوباره انداختی تو یه پنل BackGround در حالی که شما backPic رو واسه پنل BackGround ست کردی...باید یه پنل داشته باشی که همه اینا توش باشه و فقط کافیه backPic رو واسه اون ست کنی و clock و ... هم JLabel باشه
EDIT:
/**
* @author avb
*/
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class CalendarFrame extends JFrame {
public CalendarFrame() {
setSize(new Dimension(450, 500));
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_C LOSE);
setLocation(500, 50);
BackGround bk = new BackGround();
add(bk);
}
public static void main(String args[]) {
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
EventQueue.invokeLater(() -> new CalendarFrame().setVisible(true));
}
//
// private String calenderSetter() {
// String solarMonth = "";
// Scanner scan = new Scanner(System.in);
// System.out.println("enter day");
// int day_Of_Month = scan.nextInt();
// System.out.println("enter mon");
// int month = scan.nextInt();
// System.out.println(day_Of_Month + " =is day ");
// System.out.println(month + " =is month");
// switch (month) {
// case 1:
// if (day_Of_Month >= 21) {
// solarMonth = "بهمن";
// }
// if (day_Of_Month < 21) {
// solarMonth = "دی";
// }
// break;
// case 2:
// if (day_Of_Month >= 20) {
// solarMonth = "اسفند";
// }
// if (day_Of_Month < 20) {
// solarMonth = "بهمن";
// }
// break;
// case 3:
// if (day_Of_Month >= 21) {
// solarMonth = "فروردین";
// }
// if (day_Of_Month < 21) {
// solarMonth = "اسفند";
// }
// break;
// case 4:
// if (day_Of_Month >= 21) {
// solarMonth = "اردیبهشت";
// }
// if (day_Of_Month < 21) {
// solarMonth = "فروردین";
// }
// break;
// case 5:
// if (day_Of_Month >= 22) {
// solarMonth = "خرداد";
// }
// if (day_Of_Month < 21) {
// solarMonth = "اردیبهشت";
// }
// break;
// case 6:
// if (day_Of_Month >= 22) {
// solarMonth = "تیر";
// }
// if (day_Of_Month < 22) {
// solarMonth = "خرداد";
// }
// break;
// case 7:
// if (day_Of_Month >= 23) {
// solarMonth = "مرداد";
// }
// if (day_Of_Month < 22) {
// solarMonth = "تیر";
// }
// break;
// case 8:
// if (day_Of_Month >= 23) {
// solarMonth = "شهریور";
// }
// if (day_Of_Month < 22) {
// solarMonth = "مرداد";
// }
// break;
// case 9:
// if (day_Of_Month >= 23) {
// solarMonth = "مهر";
// }
// if (day_Of_Month < 22) {
// solarMonth = "شهریور";
// }
// break;
// case 10:
// if (day_Of_Month >= 23) {
// solarMonth = "آبان";
// }
// if (day_Of_Month < 21) {
// solarMonth = "مهر";
// }
// break;
// case 11:
// if (day_Of_Month >= 22) {
// solarMonth = "آذر";
// }
// if (day_Of_Month < 21) {
// solarMonth = "آبان";
// }
// break;
// case 12:
// if (day_Of_Month >= 22) {
// solarMonth = "دی";
// }
// if (day_Of_Month < 20) {
// solarMonth = "آذر";
// }
// break;
// }
// System.out.println("mahe shamsi = " + solarMonth);
// System.out.println("***************finish********* *********");
// return solarMonth;
// }
private class BackGround extends JPanel {
public Image backPic;
public BackGround() {
try {
backPic = ImageIO.read(getClass().getResource("/resource/1.png"));
} catch (IOException ex) {
ex.printStackTrace();
}
JLabel timeLabel = new JLabel();
JLabel monLabel = new JLabel();
add(timeLabel, BorderLayout.NORTH);
add(monLabel, BorderLayout.SOUTH);
Thread threadClock = new Thread(() -> {
Calendar cal = Calendar.getInstance();
cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
System.out.println(sdf.format(cal.getTime()));
timeLabel.setFont(new Font("MV Boli", Font.BOLD, 55));
timeLabel.setForeground(Color.BLACK);
while (true) {
cal = Calendar.getInstance();
cal.getTime();
sdf = new SimpleDateFormat("HH:mm:ss");
timeLabel.setText(sdf.format(cal.getTime()));
}
});
threadClock.start();
Thread threadMon = new Thread(() -> {
monLabel.setFont(new Font("MV Boli", Font.BOLD, 55));
monLabel.setForeground(Color.red);
monLabel.setPreferredSize(new Dimension(300, 100));
monLabel.setMaximumSize(new Dimension(300, 100));
monLabel.setMinimumSize(new Dimension(300, 100));
//...
});
threadMon.start();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(backPic, 0, 0, getWidth(), getHeight(), this);
}
}
}